: : 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
: : end loop
: :
: : 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.
: :
:
:
: Hello!
: primarily, its totally no matter which algo you are using for your
: 6 out of 49 lottery program, as long as it WORKS properly, without duplicates and "number holes" or
: repetitious series of numbers(in BASIC i would prevent this by the RANDOMIZE TIMER statement, and its ok)
: so just write YOUR code!
:
: But btw, could you tell me where to get a good C/C++ Interpreter/Compiler/Development environment from?
: I would like to start programming in C/C++/VisualC++ too, after BASIC,
: VisualBASIC and a little Pascal and ASM(with Microsofts DEBUG!!

).
: What Compiler/Environment are you using?
:
: Thank you in advance
: Mac
:
Actually, it could matter, certain algorithms are faster.
I used one in my c++ class a couple years ago. (I've since upgraded to assembler, so I don't remember c++ syntax very well...) It works by making an array of booleans with as many elements as random numbers to be generated. Then, it checks each new number's element in the array, and if it's false, it makes it true and uses that number. If it's true already, it regenerates that number and tries again, until it succeeds.