Mail Archives: djgpp/1998/06/01/17:30:25
Ryan writes:
>What i did, which was probably a bit of overkill in guaranteeing
>randomness, was seed the number a bunch of times during initialization
>it looks like this:
>
>uclock() // to start timing
>for (i = 0; i <= 4 ; i++){
> for (i = rand() % 2000; i >= 1600 ; i--);
> srand(uclock() + biostime());
>}
This is redundant, becuase each call to srand() totally replaces the
existing state of the RNG, so only your very last call will have any
effect. It also doesn't make much sense to use uclock() for this,
because that returns the time delay from when it was first called, which
will always be zero if you run this code at the very start of your
program.
By far the most usual and portable way to seed the system is simply to
call srand(time(NULL)). That works perfectly except in the (unlikely)
case that your program is run multiple times within a single second.
--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Miracles are nothing if you've got the wrong intentions" - Mike Keneally
- Raw text -