October 9th, 2002, 08:57 AM
How can I generate numbers w/out duplicates...
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???
October 9th, 2002, 09:04 AM
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:
JeffB - hope it helps
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.