views:

197

answers:

3

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 can only be used on *nix systems.

+2  A: 

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.

Matthew Flaschen
Along this line, you might want to look into hardware random number generators. However, this would require great dedication to the cause.
zdav
This doesn't need to degenerate into another pseudorandom/random number discussion. What you need for Monte Carlo simulations is pseudorandom numbers with a very large period.
WhirlWind
A: 

Why your arbitrary precision requirement? There is no "random number between 0 and infinity". You always need a range.

frunsi
Your question should probably have been posted as a comment to the original question.
zdav
@frunsi: yes, a range is required. However, I don't want the range to be bounded in the way it is when defining an integer in C (where, for example, uint32_t is bound between 0 and UINT32_MAX), so it's not a "random number between 0 and infinity", but I want the range to be defined by me. Also, say we have a "true" random number generator, and it's outputs are inclusively bounded between 0 and 1; it would still be a random number if we take a certain number of outputs, and read a concatenation as a binary number; however, we have chosen the precision (e.g. 0101(base 2)=5 with 4 outputs).
Yktula
+2  A: 

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.

ima