-
October 9th, 2002, 08:57 AM
#1
How can I generate numbers w/out duplicates...
Hi all,
I want to be able to generate 6 random numbers from 1 to 20 and place each of those numbers into a label(of which there are 6).
But each number must be unique, i.e. no duplicates.
Any possible code for this???
Thanks
Mark
-
October 9th, 2002, 09:04 AM
#2
The first technic would be to generated a random number, look for an array to see if it has already been generated, and continue like that.
But a better method would be to generate an array of 20 (with the number from 1 to 20) and shuffle the array (you know, swap elements) a X number of times, and after just take the number from indice 0 to 5, look at this example:
http://www.codeguru.com/forum/showth...&threadid=5650
JeffB - hope it helps
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|