On Thursday 13 September 2007 08:45, sapphirebrand wrote: > The normal OS clock available in standard C has millisecond > precision, so if Quackle can make two moves in the same millisecond > then it would lose randomness. > > But the situation is actually worse than that, because many operating > systems (e.g., Windows) do not have clocks with millisecond > resolution! For example, on Windows the normal clock increments > in 1/18 of a second. This would leave Quackle using the same > random seeds for many, many moves in a row. > > It is true that any modern OS will have a real-time clock that has > better timing characteristics. But these are not portable code. > > Better algorithm: seed using a millisecond timer, so that Quackle > does not start up in the same state. Use an RNG that passes all tests > of randomness (e.g., KISS). Optionally, you can reseed by adding > clock() to the RNG state.
The best way to "reseed": use the user's input event stream as an entropy source. Perhaps by folding in the time of each keystroke into the current value of your RNG and reseeding based on that.
