I have 16 labels on a form andd would like to generate 16 randoms numbers,from 1 thru 16.
The only trick is that they must be unique.
I can't figure out how to do this and looked pretty much everywhere.
Any suggestions would be helpful.
Thanks.
Printable View
I have 16 labels on a form andd would like to generate 16 randoms numbers,from 1 thru 16.
The only trick is that they must be unique.
I can't figure out how to do this and looked pretty much everywhere.
Any suggestions would be helpful.
Thanks.
So you want each one to be differant but in a random order? I suggest just making it so that if the number is already used it would add 1 to the # until it's a unused #...if the # gets to 16 then it would go back to 1...
Does this help?
Also make sure you use Randomize() in your Form Load otherwise the numbers will be the same every time you run your program, the Random Function is based on your computers clock, and the first time it's built, is the only time it'll get the #'s unless you add the randomize()
Yes,
Just after posting I found a solution.
Another trick I'd also like to do is:
I have 16 labels allow the numbers 1-8 to be used, but only 2 times a piece.
Any Solution?
One way I can think of offhand is to use an array 1 throu 32 to hold your values.
Array(1)=1
Array(2)=1
Array(3)=2
Array(4)=2
Array(5)=3
Array(6)=3
.
.
.
Array(31)=16
Array(32)=16
Next do a for loop from 1 to 32,
each loop cycle pick a random array index and swap it's value with the array index by your loop counter. This has the net effect of putting your array into a random order..
Finally, make another loop that assigns lablel captions to array indexes..
Label(1).capton=Array(1)
Label(2).capton=Array(2)
etc..
If you need a code example let me know.
Woops! I meant to say Array 16 elements in size and numbers that go up to 8 (not 32)
Geez I need to switch to decaf.....