Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Classic ASP Random Letter

I would like to know if there is a way to get a random letter (from A-Z)

Thanks for any help.

like image 429
compcobalt Avatar asked Dec 01 '22 02:12

compcobalt


2 Answers

I think this is what you're looking for. Generate a Random Letter in ASP:

Function RandomNumber(LowNumber, HighNumber)
    RANDOMIZE
    RandomNumber = Round((HighNumber - LowNumber + 1) * Rnd + LowNumber)
End Function

Assign the function to a variable and pass in the LowNumber (26) and the HighNumber (97) and convert the value returned to the character it represents:

RandomLetter = CHR(RandomNumber(97,122))

You'll want your range to be between 65 and 90 (A and Z) for capital letters.

like image 90
Yuck Avatar answered Dec 06 '22 15:12

Yuck


Roger Baretto's answer fixed with Cem's hint ))

Function RandomString(iSize)
    Const VALID_TEXT = "abcdefghijklmnopqrstuvwxyz1234567890"
    Dim Length, sNewSearchTag, I

    Length = Len(VALID_TEXT)

    Randomize()

    For I = 1 To iSize            
        sNewSearchTag = sNewSearchTag & Mid(VALID_TEXT, Int(Rnd()*Length + 1), 1)
    Next

    RandomString = sNewSearchTag
End Function
like image 23
Ali Avatar answered Dec 06 '22 14:12

Ali