I know that there are other questions similar to this one, however the following question pertains to arbitrary-precision random number generation in C for use in Monte Carlo simulation.
How can we generate good quality arbitrary-precision random numbers in C, when atmospheric noise isn't always available, without relying on disk i/o or network access that would create bottlenecks?
libgmp is capable of generating random numbers, but, like other implementations of pseudo-random number generators, it requires a seed. As the manual mentions, "the system time is quite easy to guess, so if unpredictability is required then it should definitely not be the only source for the seed value."
Is there a portable/ported library for generating random numbers, or seeds for random numbers? The libgmp also mentions that "On some systems there's a special device /dev/random which provides random data better suited for use as a seed." However, /dev/random
and /dev/urandom
ca开发者_开发知识库n only be used on *nix systems.
Don't overestimate importance of seed.
Firstly, it doesn't need to be truly chaotic - only to have good distribution and not be correlated with any processes in your simulation or pseudo-random generator.
Secondly, for Monte-Carlo statistical characteristics matter, not randomness (in any sense) of a particular number.
Low bytes of high-precision time or some derivative of keyboard-mouse actions make a good seed for anything that is going to be run on a regular PC.
By definition, true random numbers require chaotic information from the real world. /dev/random often (but not always) provides this. Another option for *ix is Entropy Gathering Demon. /dev/urandom by design will happily provide non-random data, since it doesn't block when the entropy pool is exhausted.
Internet APIs that provide this include HotBits (radioactive decay), LavaRnd (CCD), and Random.org (atmospheric noise, which I realize you don't want). See also Hardware random number generator
This device (no affiliation) has drivers for Windows and *ix.
Why your arbitrary precision requirement? There is no "random number between 0 and infinity". You always need a range.
精彩评论