Function LCharRand(n) '生成n位随机小写字母
For i=1 to n
Randomize
temp = cint(25*Rnd)
temp = temp +97
LCharRand = LCharRand & chr(temp)
Next
End Function
msgbox LCharRand(5),,"生成n位随机小写字母"
Function UCharRand(n) '生成n位随机大写字母
For i=1 to n
Randomize
temp = cint(25*Rnd)
temp = temp +65
UCharRand = UCharRand & chr(temp)
Next
End Function
msgbox UCharRand(5),,"生成n位随机大写字母"
Function allRand(n) '生成n位随机数字字母子组合
For i=1 to n
Randomize
temp = cint(25*Rnd)
If temp mod 2 = 0 then
temp = temp + 97
ElseIf temp < 9 then
temp = temp + 48
Else
temp = temp + 65
End If
allRand = allRand & chr(temp)
Next
End Function
msgbox allRand(5),,"生成n位随机数字字母子组合"
把以上内容存为rand.vbs双击运行,可以看到效果。