Generate Random String


Generate Random String For a Given Length

Function RandomString(iLen,blnAlphaNumeric)
    strCharSet="abcdefghijklmnopqstuvwxyz"
    Randomize
    If blnAlphaNumeric Then
        For i=1To iLen
            strCharSet = strCharSet & "1234567890"
            strRandom = strRandom & Mid(strCharSet,Int(Len(strCharSet)-1)*Rnd+1,1)
        Next
    Else
        For i=1To iLen
            strRandom = strRandom & Mid(strCharSet,Int(Len(strCharSet)-1)*Rnd+1,1)
        Next
    EndIf
    RandomString = strRandom
EndFunction

MsgBox RandomString(5,True) 'True for Alpha Numeric string
MsgBox RandomString(5,False) 'False for normal string

No comments:

Post a Comment