How do I produce quality random numbers without maintaining internal state?

73 Views Asked by At

Normally, you initialize some kind of random number generator object with a seed (usually, the time) at the start of the application and then keep it around and ask it for random numbers. This object is the state.

I have an application that starts, generates one number, then exits. Since the RNG is initialized from the clock, I still have some randomness, but standard RNGs provided by frameworks are not meant to be used like this (asking the first number of each seed), so the quality of the generated numbers is poor. How do I generate quality random numbers without saving the state of the RNG between the invocations of my application?

I'm doing this on Windows, if it matters. Getting extra sources of randomness is fine, but leaving data behind (e.g. writing to disk) is not allowed.

1

There are 1 best solutions below

1
On BEST ANSWER

On Windows there is a secure random generator, CryptGenRandom, which will do all that for you. Most languages have a SecureRandom class, dev/random or similar to access it. Other OS's will have similar arrangements. Basically they import entropy from within the system to seed their own generator.

For a more general solution you could use a hardware RNG on a card, such as the Quantis RNG.