Mail Archives: djgpp/1996/11/21/08:41:43
Eli Zaretskii wrote:
>
> Not true. The following program, compiled with DJGPP v2.01, will
> continuosly print random integers until you press a key. It works for
> me. So there is no need to call srand.
>
Still, it *is* bad practice not to initalise rand() with srand() in
portable programs: many implementations of rand() use linear congruential
generators: they calculate
y=ax+b mod(c) (where x is the previous value, and y the output of rand())
Now, some implementations use b=0, as it saves an add per call, an can be
as good as the other one...
In this case, you can use any seed *except* 0, which will always output
the same value (0)...
As rand() is an ANSI function, but as its implementation can vary from
one library to the other, it is wise to always seed rand() in portable
programs, and *never* use a 0 seed.
- Raw text -