|
-
Jan 12th, 2004, 08:02 PM
#1
Thread Starter
Addicted Member
Random Numbers
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.
-
Jan 12th, 2004, 08:11 PM
#2
Lively Member
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()
It is like wiping your ass with silk, I love it!
-
Jan 12th, 2004, 08:16 PM
#3
Thread Starter
Addicted Member
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?
-
Feb 18th, 2004, 03:54 PM
#4
Addicted Member
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.
-
Feb 18th, 2004, 03:57 PM
#5
Addicted Member
Woops! You said 16...
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.....
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
|