小古Blog
两个ASP随机生成[a-z,A-Z,0-9]的函数
2012-1-4 小古

<%

    function fRndStr(num)

        if isNumeric(num)=false then exit function else num=int(num)

        dim i, j

        dim rndStr(61)

        

        for j=0 to 9:rndStr(j)=cStr(j):next 

        j=10:for i=65 to 90:rndStr(j)=chr(i):j=j+1:next

        j=36:for i=97 to 122:rndStr(j)=chr(i):j=j+1:next

        

        j=0:randomize

        do until j=num:fRndStr=fRndStr+rndStr(Int((61 - 0 + 1) * Rnd + 0)):j=j+1:loop

        erase rndStr

    end function


Function Createpass(num)

  Dim Ran,i,LengthNum

  if isNumeric(num)=false then exit function else num=int(num)

  Createpass=""

  For i=1 To num

   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


response.write fRndStr(10)

response.write "<br/>"

response.write Createpass(10)

%>

发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容