I'm toying around with a program in C++ that picks a user defined amount of number sets (ie: 6 numbers per set, and the user may want 100 sets) and then gives me a count of how many times each number was picked (right now its 1 to 49).
My problem is that when I am picking a set of 6 numbers I am wracking my brains to find a way to make it pick only 6 unique numbers...
Right now I have 2 loops and somehow it doesn't seem to be elegant.
do loop until 6 numbers are actually picked
- get a random number (I'm using RAND right now)
- start another loop (6 times)
- check latest pick against the numbers picked before
(stored in a temporary array)
- end loop, if number wasn't found, then add to set and
increment the numbers that were picked
I'm just curious if someone might have a nicer way to do it, I can post code if needed, but I'm interested in the algorithm since I keep playing with this thing as a way to practice coding C++ (I learned to program in C and C++ but been working COBOL and mainframes for the last 5 years so I never did anything with it beyond the basics I was taught in college and I want to change that).
Thanks in advance for your help, I've been reading the boards for weeks but its my first question...this place totally rocks.