Re: lottery number thing problem
From: Andreas Goebel (a-goebel_at_at__gmx.de)
Date: Wed, 12 Nov 2003 22:32:17 +0100
Chris Theis wrote:
> "Chris Dams" <email@example.com> wrote in message
> [SNIP]> > while (num_count <=5) //i.e. while all 6 numbers have not yet been
>>> //initialise random number generator
>>> time_t t;
>>> srand(unsigned (time(&t)));
>>The srand should not be inside the loop. Move it out of it.
> I'd even suggest to move it out of the whole function into main() 'cause
> there is certainly no point in re-seeding the RNG and this might become a
> pitfall sometime later!
I donīt know if I am leading the original poster to far away, but as
this surely is a c++ listing I would do this completely different:
- create a set, put the 49 Numbers into it
- do a random shuffle with the set
- get the first six numbers out of the set and put them in a vector
- sort the vector, cout the numbers
You will need to read the documentation to the following headers:
<algorithm> - you need that for the random shuffle and for the sorting
(look for random_shuffle and sort).
If you want to do the actual sorting yourself you will need a sorting
algorithm. You can learn very much if you try to invent your own. How
would you sort playing cards? If you want to program this yourself you
should stick to the array.
Best regards, Andreas