How to Generate a Random alphanumeric number

35 views
Skip to first unread message

Mahesh

unread,
Apr 1, 2015, 7:36:29 AM4/1/15
to mercu...@googlegroups.com
Need to Generate a random alpha numeric number where the first two char should be alphabets and rest of them should be numbers

example AB123456, Ac5356 MA4567



Dev Kumar

unread,
Apr 3, 2015, 3:19:37 AM4/3/15
to mercu...@googlegroups.com
Check this Out and update as per ur req

Public Function GetRandomString(ByVal iLength As Integer) As String
    Dim intMax, iLoop, k, intValue, strChar, strName, intNum

    ' Specify the alphabet of characters to use.
    Const Chars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    ' Specify length of names.
    'intMax = 5
    intMax = iLength
    ' Specify number of names to generate.
    

    Randomize

    strName = ""
    For k = 1 To intMax
        ' Retrieve random digit between 0 and 25 (26 possible characters).
        intValue = Fix(62 * Rnd())
        ' Convert to character in allowed alphabet.
        strChar = Mid(Chars, intValue + 1, 1)
        ' Build the name.
        strName = strName & strChar
    Next

    GetRandomString = strName
End Function

Venkat Reddy Bandaru

unread,
Apr 3, 2015, 5:04:24 AM4/3/15
to mercu...@googlegroups.com
Hi Mahesh,
Please find the below solution and confirm me

    ' Specify the alphabet of characters to use.
    Const Chars = "abcdefghijklmnopqrstuvwxyz"
    strName = ""
    For k = 1 To 2
        ' Retrieve random digit between 0 and 25 (26 possible characters).
intValue= RandomNumber(1,25)
        ' Convert to character in allowed alphabet.
        strChar = Mid(Chars, intValue, 1)
        ' Build the name.
        strName = strName & strChar
    Next
rValue= RandomNumber(100,999)
ExpValue=strName&rValue
Msgbox ExpValue

 
Thanks & Regards,
Venkat Reddy Bandaru


--
--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to Mercu...@googlegroups.com
To unsubscribe from this group, send email to
MercuryQTP+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en

---
You received this message because you are subscribed to the Google Groups "QTP - HP Quick Test Professional - Automated Software Testing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mercuryqtp+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages