Is `/dev/urandom` suitable for simulation purpose? Is `/dev/urandom` suitable for simulation purpose? unix unix

Is `/dev/urandom` suitable for simulation purpose?


In the underlying implementation of /dev/urandom is a CSPRNG, the output pool of which has a maximal period of less than 2^(26∗32) − 1, which is then fed into SHA-1 to produce output for /dev/urandom. As such, urandom can obviously produce the amount of random numbers you want, however it can not offer you reproducible results - you will have to cache the sequence you get yourself.

You do not have to worry about what happens when the entropy pool is estimated to be depleted, /dev/urandom will output whatever you request of it. The "theoretical attacks" the urandom(4) man page speaks of are nonexistent. (the "issue" is a huge misunderstanding of what "entropy estimation" is)

Many other PRNGs with large periods exist which reproducible seeding: the Mersenne Twister in C++, xorshift PRNGs, etc. You should be able to adapt any PRNG to the distribution which is suitable for your purposes.


No, /dev/random and /dev/urandom are designed for cryptographic applications where you want very high entropy in exchange for speed. They run very slowly compared to a good non-CS PRNG, and so will not give you enough samples for simulation or Monte Carlo integration.

For these, use a fast but good-quality PRNG like XOR-shift+ or Mersenne Twister. You can seed the PRNG with data from /dev/urandom if you don't need repeatability.


As to the "quality of random bytes from [/dev/urandom] when the entropy pool is depleted", O'Neill (2014) points out that designers of generators for cryptographic purposes do "not have the same concerns about statistical properties (such as uniformity) compared to general-purpose random number generators".

This may explain why the output of /dev/urandom fails statistical tests even though the consensus seems to be that the output of /dev/urandom is good even after depletion.

If you want to combine the properties of /dev/urandom and a standard generator for simulation purposes such as Mersenne Twister, my suggestion would be to exor both data streams. The approaches are sufficiently different that they should not cancel each other out.

Ref: http://www.pcg-random.org/paper.html