PHP: Function Createpass(LengthNum) Dim Ran,i '默认15位 if Not IsNumeric(LengthNum) then LengthNum=15 Createpass="" For i=1 To LengthNum Randomize Ran = CInt(Rnd * 2) Randomize If Ran = 0 Then Ran = CInt(Rnd * 25) + 97 Createpass =Createpass& UCase(Chr(Ran)) ElseIf Ran = 1 Then Ran = CInt(Rnd * 9) Createpass = Createpass & Ran ElseIf Ran = 2 Then Ran = CInt(Rnd * 25) + 97 Createpass =Createpass& Chr(Ran) End If Next End Function '调用.... Dim nums nums=Createpass(15) response.write nums
我来补充一个: MyRandc(n) 生成随机字符,n为字符的个数 如: response.write MyRandn(10) 输出10个随机字符 function MyRandc(n) '生成随机字符,n为字符的个数 dim thechr thechr = "" for i=1 to n dim zNum,zNum2 Randomize zNum = cint(25*Rnd) zNum2 = cint(10*Rnd) if zNum2 mod 2 = 0 then zNum = zNum + 97 else zNum = zNum + 65 end if thechr = thechr & chr(zNum) next MyRandc = thechr end function
再来一个: 生成n到x之间的随机数. GetRnd(n,x) function GetRnd(min,max) Randomize GetRnd = Int((max - min + 1) * Rnd + min) end function