Mail Archives: djgpp/1996/11/21/07:04:32
> It may have been a bug in the v2.00 version. Before I answered your
> question I looked into the library source code for rand() and srand()
> (in src/libc/ansi/stdlib/rand.c if you must know). The seed value for
> the randomizer is a static global variable, which means it is _always_
> initialized to zero when your program is run. I cannot think of any way
> in which v2.00 could have handled the coding without initializing to
> zero, unless it ran srand() by default in startup (a kludgy solution).
I don't know if it is declared in a standard, but I think rand()
should always return the same sequence if srand is not used.
Of course, I can do srand(0), but usually I don't have to.
The use of such non-random sequences is very simple - debugging.
If I want to debug my program which uses random numbers, I want
it to use the same 'random' numbers on each invocation until it
works correctly.
- Raw text -