"Lionel B" wrote:
> On Wed, 28 May 2008 14:26:27 +0200, bilgekhan wrote:
> > "Pascal J. Bourguignon" wrote:
> >>
> >> If you care so little about your randomness, you could as well write
> >> bool f=((rand()%100)==(rand()%100));
> >
> > Have you tried this in a loop of say 1 million times and counted the
> > hits? I think theoretically there should be about 10,000 matches. What
> > result do you get?
> > Maybe 0 ? 
>
> Why do you think you might get 0 ?
Because it is the same sequence of the RNG...

A seed sequence of rand() always generates
RAND_MAX different random numbers.
So within a sequence it cannot generate the same number twice.
After generating RAND_MAX numbers the sequence
starts over again to generate again the same sequence of numbers.
Since the program is within the same sequence
and since the two numbers are generated together
it never can happen that these 2 numbers somehow match...
Ie. rand() is predictable: if you generate RAND_MAX numbers
and store them somewhere then you can look there what random
number it will generate next.

But this works only if you don't change the rand sequence
by calling srand() a second time.
I did some experiments and I come to the conclusion
that it is not NOT possible to let 1 RNG _correctly_ generate
2 independent random numbers.
One has to solve it cleverly via just 1 random number only
as was shown by Kai-Uwe Bux (cf. his posting).