RANDOMIZE

1. HASNAIN RAZA Guest

## RANDOMIZE

IS IT POSSIBLE TO RANDOMIZE ALPHABETS RATHER THAN NUMBERS

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## please don't YELL! ... and yes...

Sure. See the ASPFAQs: http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=114<BR><BR>So if you wanted to randomly select the 26 letters of the alphabet, you could do<BR><BR>&#060;%<BR>alphabet = Array( "a","b","c","d"....,"y","z" )<BR>shuffledAlphabet = Shuffle( alphabet, 26 )<BR>%&#062;<BR><BR>Where you are using the "Shuffle" function that is given on that page.<BR><BR>Hokay?<BR><BR>

3. Nils Bilhorn Guest

## RE: RANDOMIZE

I&#039;m not exactly sure that I understand what you wish to achieve.<BR><BR>If you want a random letter you can get a random number between 65 and 91 and the use the chr function that returns a letter given a the ascii code for that number<BR><BR>Randomize<BR>mynum = 64 + 26*rnd() <BR>letter = Chr(mynum) <BR><BR>Chr(65) Returns A.<BR>Chr(66) Returns B. etc.

4. New ASP Guest

## RE: RANDOMIZE

yes! You can.<BR><BR>RANDOMIZE<BR>response.write chr(Int((90 - 65 + 1) * Rnd + 65))<BR><BR>

5. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## RE: RANDOMIZE

Have you thought of randomizing the ASCII values

6. Senior Member
Join Date
Dec 1969
Posts
96,118

## Oops! A bug in what I showed...

The "Shuffle" function in that ASPFAQs page carefully notes that it *ignores* element zero of the array it is given. So you could fix that by either doing this:<BR><BR>&#060;%<BR>alphabet = Array( "", "a","b","c","d"....,"y","z" )<BR>shuffledAlphabet = Shuffle( alphabet, 26 )<BR>%&#062;<BR><BR>(see the "" element I added on the front of the array? Now when you get the results back, you just ignore the first element of the array).<BR><BR>*OR* you could make a minor rewrite of the Shuffle function that, just incidentally, always shuffles the entire array it is given:<BR><BR>&#060;%<BR>&#039; shuffle the *entire* array as given to the function:<BR>Function Shuffle( inArray )<BR>&nbsp; &nbsp; outmax = UBound( inArray ) <BR>&nbsp; &nbsp; incnt = outmax <BR>&nbsp; &nbsp; dim outArray<BR>&nbsp; &nbsp; redim outArray( outmax )<BR>&nbsp; &nbsp; For i = 0 To outmax<BR>&nbsp; &nbsp; &nbsp; &nbsp; choose = Int( (incnt+1) * Rnd(1) ) <BR>&nbsp; &nbsp; &nbsp; &nbsp; outArray( i ) = inArray( choose )<BR>&nbsp; &nbsp; &nbsp; &nbsp; inArray( choose ) = inArray( incnt )<BR>&nbsp; &nbsp; &nbsp; &nbsp; incnt = incnt - 1<BR>&nbsp; &nbsp; Next<BR>&nbsp; &nbsp; Shuffle = outArray<BR>End Function<BR>...<BR>alphabet = Array( "a","b","c","d"....,"y","z" )<BR>shuffledAlphabet = Shuffle( alphabet )<BR>shuffledAlphabetAsString = Join( shuffledAlphabet, "" )<BR>%&#062;<BR><BR><BR><BR><BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•