Randomize an Array

# Thread: Randomize an Array

1. Senior Member
Join Date
Dec 1969
Posts
590

## Randomize an Array

I would like to find a way to randomize an array? Are there any functions that do this? Thanks!

2. New ASP Guest

## Mind explain more? <eof>

.

3. Senior Member
Join Date
Dec 1969
Posts
614

## What, shuffle array contents? Try this

myArray=array(1,2,3,4,5,6,7,8,9,10)<BR><BR> y=ubound(myArray)<BR> for x=1 to 100 &#039;number of shuffles to perform<BR> randomize <BR> x1= Int((y - 1) * Rnd) &#039;new random number (0-y)<BR> x2= Int((y - 1) * Rnd) &#039;new random number (0-y)<BR> tmp=myArray(x1) &#039;shuffle 2 elements<BR> myArray(x1)=myArray(x2)<BR> myArray(x2)=tmp<BR> next<BR> <BR> for x=0 to y<BR> document.write (myArray(x) & " ")<BR> next<BR>

4. New ASP Guest

## RE: What, shuffle array contents? Try this

The last 2 numbers are always the same

5. Senior Member
Join Date
Dec 1969
Posts
614

## fair do's : original code had a *feature* :-/

for z=1 to 20<BR>myArray=array(1,2,3,4,5,6,7,8,9,10)<BR><BR> y=ubound(myArray)<BR> for x=1 to 100 &#039;number of shuffles to perform<BR> randomize <BR> x1= Int((y + 1) * Rnd) &#039;new random number (0-y)<BR> x2= Int((y + 1) * Rnd) &#039;new random number (0-y)<BR> tmp=myArray(x1) &#039;shuffle 2 elements<BR> myArray(x1)=myArray(x2)<BR> myArray(x2)=tmp<BR> next<BR> <BR> for x=0 to y<BR> document.write (myArray(x) & " ")<BR> next<BR> document.write ("<BR>")<BR>next<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
•