# Re: lottery number thing problem

From: Andreas Goebel (a-goebel_at_at__gmx.de)
Date: 11/12/03

```Date: Wed, 12 Nov 2003 22:32:17 +0100

```

Chris Theis wrote:

> "Chris Dams" <chrisd@gamow.sci.kun.nl> wrote in message
> news:bot232\$ekd\$1@gamow.sci.kun.nl...
>
>>Hello,
>>
>
> [SNIP]> > while (num_count <=5) //i.e. while all 6 numbers have not yet been
> drawn.
>
>>> {
>>> //initialise random number generator
>>> time_t t;
>>> srand(unsigned (time(&t)));
>>
>>The srand should not be inside the loop. Move it out of it.
>>
>
> [SNIP]
>
> 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!
>
> Regards
> Chris
>
>
Hello,

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

<set>
<vector>
<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

## Relevant Pages

• Re: attempt at qsort implementation
... qsortis not required to implement any particular sort algorithm. ... It's just supposed to sort. ... out of order by sorting them and returning the first one. ... A recursive bogosort uses bogosort to sort the possible orders by ...
(comp.lang.c)
• Re: allowing my AI to dynamically change its own structure
... the only kind of sort you knew about. ... If you have a program with a goal of sorting lists of numbers, ... algorithm, ... from the very low level model you seem to prefer? ...
(comp.ai)
• Re: Sorting algorithm when comparison is heavy
... optimal way of sorting such elements (in other words, ... I would consider some good sort algorithm like quicksort together ... You suggest using pointers, so I think the above applies. ...
(comp.programming)
• Re: sort on more than one key?
... I can sort on one key no problem.But what ... > sorting on more than one key, for example by last name then by first name. ... unstable) and in the compare function code the following for any pair ... key using a stable algorithm such as a nice "bubble" sort ...
(comp.programming)
• Re: finding max and min integers - newbie question
... Chris Theis wrote: ... > Why not sort the vector and thus you have the min & the max value at once? ... Because it is an overkill that will generate more heat than light. ... Sorting the vector might work in case when one needs to find min/max ...
(comp.lang.cpp)