# Hardware random number generator Vs. Pseudo random number generator in the battlefield of Markov Chain Monte Carlo processes

I'm implementing a Markov Chain Monte Carlo process for a Quantum Monte Carlo routine, in every book and paper I've read so far the success of the routine and quality of the results strongly depends on the random number generator.

Well I've chosen to implement the code in C++ 2011, and I'm presented with a fair wide selection of pseudo random number generator engines and a non deterministic random number generator (based on the hardware random number generator that most of the modern computers have).

Which is the physical or statistical reason to chose a good random number generator?, and which is best for this purpose, a well studied pseudo random number generator engine or the (I think unpredictable) hardware random number generator?

You can see the engines available here.

• Thenks for the migration @dmckee – Oscar David Arbeláez Apr 16 '13 at 22:00

There is no reason to use hardware random number generation for anything other than full cryptography. For everything else, including computational physics, pseudorandom generators are fine. I would suggest using the Random123 library of Salmon et al.: it's fast, trivially parallelizable, and strong (in particular stronger than Mersenne Twister).

It is important to use a high quality generator, though the quality requirements depend very strongly on the application. An example of what can go wrong: in explicit solvent molecular dynamics, it is common to take time steps on the order of 1 femtosecond ($10^{-15}$ s). A generator with a period of only $2^{32}$ evaluated once per step would be similar to a radiative input with a frequency of $0.2$ MHz. If this is a physically interesting frequency for the system in question, the results would be invalid.

Happily, since there are numerous random generators which both fast and strong enough for essentially all noncryptographic purposes (including both Random123 and Mersenne Twister), there's no real tradeoff in practice.

• Thanks, I'm happy there is so much people with this kind of very specific knowledge that are willing to solve other's doubts, I'll go for the Mersenne Twister for development, then I'l try Random123, thanks again. – Oscar David Arbeláez Apr 16 '13 at 22:02
• Yep, Mersenne Twister will do fine. The main reason to use Random123 is easy deterministic parallelism. I believe it also has a C++11 style interface, so the switch should be extremely easy if you end up making it. – Geoffrey Irving Apr 16 '13 at 22:21

Geoffrey already answered the question, but I'd like to add another perspective to it. One of the things you will have to do one way or another is to debug code. It may not necessarily be that you have to debug anything that has to do with the random numbers themselves, but, say, a bug in the function evaluation that depends on the randomly selected sample.

In this case, it is immensely awkward if you use a random number generator that is not deterministic, i.e., that does not produce the same numbers in every run: because if you do use a non-deterministic random number generator and you see a bug, you will not be able to reproduce it the next time you call your program. As a consequence, I've always told my students to use a deterministic random number generator using a fixed seed. Today's RNGs are good enough that one doesn't really have to be afraid that there is not enough entropy in their number sequences, and their deterministic nature allows you to debug programs.