ShuffleNumbers

How do you make random numbers that don't repeat, like "5 6 7 1 3 9 10 4 2 8"?
Or how about non-repeating strings like "Hi" Hello" "Bye" "Goodbye"?

Simple.

Put your numbers in an array, like so:

```
' for 10 non-repeating numbers from 1 to 10! The general formula is "min TO max"
' or "min TO min + length - 1"
DIM SHARED numb1%(1 TO 10)

'Now initialize them:
FOR i% = 1 TO 10
numb1(i%) = i%
NEXT i%

' Now shuffle them. Doesn't matter very much how many times you do it, but I like this.
' Shuffles each # at least once:

FOR i% = 1 TO 10 '(min to max)
j% = INT(RND * 10) + 1
SWAP numb1(i%), numb1(j%)
NEXT i%

'Now display:
FOR i% = 1 TO 10
PRINT numb1(i%)
NEXT i%

```

FOR STRING ARRAYS, DO THE SAME THING!! (just substitute the "%" to "\$".

-Agamemnus

and... Mango, and a billion other forum "regulars"... not to downplay your role in this extraordinary finding, Mango. ;)

ShuffleNumbers - page last edited 2003-10-12 12:53:02 by 172.141.115.162 (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster