Mail Archives: djgpp/1998/03/27/06:34:19
Noam Rotem wrote:
>
> Can we somehow use the value of IP register combined with the time element to
> set a better seed and unpredictable sequences of random numbers?
>
I am not sure this would increase to the quality. In particular, it will
go wrong if you call the same program twice in a row, the IP register
will have the same value when the srand() function is called...
If srand(time()) does not work (as Hans-Bernhard, I think the risk is
more with two users starting the program at the same time, for instance
in the case of a multiplayer game, than with the program needing less
than a second to run), two kinds of solutions seem possible:
1- you could seed rand() with a timer function having lower granularity
than the second, either available on your OS, or predefined as a TSR, you
will not remove the problem, but make it less likely.
2- for better security, you could have a seeding procedures which
guarantees that successive runs of your program never have the same seed.
For instance, the seed could be an environment variable, which would be
incremented every time srand() is called. In such case, though, you will
have to check whether two series seeded by correlated seeds, like
seed_n+1 = seed_n + 1 are not correlated... as far as I know, little
theory is available on this subject.
You could also resort on more elaborate schemes, like reading seeds from
a precalculated file or array, generate by a RNG (seeded by time(), this
array certainly will not be generated more than once per second).
Francois
- Raw text -