日期:2014-05-17 浏览次数:20960 次
写个函数 <% '******************************************** '功能:获取指定长度的随机数和字母 '参数: ' length:要获取的随机字符串长度 ' mode: 1 数字 ' 2 小写字母 ' 3 大写字母 ' 4 数字和小写字母 ' 5 数字和大写字母 ' 6 小写字母和大写字母 ' 7 数字、小写字母和大写字母 '******************************************** Function Gen(length, mode) Dim rndString, rndChar, i, Arr() Randomize Select Case mode Case 1 '数字 For i = 1 To length rndChar = Cstr(Chr((57 - 48) * rnd + 48)) rndString = rndString & rndChar Next Case 2 '小写字母 For i = 1 To length rndChar = Cstr(Chr((122 - 97) * rnd + 97)) rndString = rndString & rndChar Next Case 3 '大写字母 For i = 1 To length rndChar = Cstr(Chr((90 - 65) * rnd + 65)) rndString = rndString & rndChar Next Case 4 '数字和小写字母 ReDim Arr(35) For i = 0 To 9 Arr(i) = CStr(i) Next For i = 10 To 35 Arr(i) = CStr(Chr(i + 87)) Next For i = 1 To length index = Int((35 - 0) * rnd + 0) rndChar = Arr(index) rndString = rndString & rndChar Next Case 5 '数字和大写字母 ReDim Arr(35) For i = 0 To 9 Arr(i) = CStr(i) Next For i = 10 To 35 Arr(i) = CStr(Chr(i + 55)) Next For i = 1 To length index = Int((35 - 0) * rnd + 0) rndChar = Arr(index) rndString = rndString & rndChar Next Case 6 '小写字母和大写字母 ReDim Arr(51) For i = 0 To 25 Arr(i) = CStr(Chr(i + 97)) Next For i = 26 To 51 Arr(i) = CStr(Chr(i + 39)) Next For i = 1 To length index = Int((51 - 0) * rnd + 0) rndCh