Mail Archives: djgpp/1999/04/06/16:38:04
Crousto wrote:
>
> The help file speaks about 2 functions : rand() and random(). I've noticed
> that rand (or random, i don't remember ;) return always the same sequence
> even with a previous srandom(biostime(0,0)), but the other one works fine.
Can you show an example of this? Whichever one does this, it's a bug.
> And it's a very good random generator : according to Bjarne Stroustrup
> (C++'s creator), low-order bits of a random generator are often suspect, so
> rand()%n is not a good way of generating a random number between 0 and n-1
> (he tips to use "(double(rand())/RAND_MAX)*n" ). BUT i've tested rand()%n,
> and it gives a very good repartition... So, DJGPP is the best C
> implementation!!! ;)
In theory, `random' should be a better RNG, especially if you use some
of its more complex modes (see the source). `rand' is just a linear
congruential RNG, though a good one.
However, `rand' is ANSI and `random' isn't. (The distinction between
their algorithms is brought about by some obscure legal issues.)
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -