# Pseudo-random number generation algorithms

What algorithms are used in modern and good-quality random number generators?

-
Retagged "random-variate" to "random-variable" for consistency with similar questions. –  whuber Aug 25 '10 at 14:14

In R, the default setting for random number generation are:

1. For U(0,1), use the Mersenne-Twister algorithm
2. For Guassian numbers use the numerical inversion of the standard normal distribution function.

You can easily check this, viz.

> RNGkind()
[1] "Mersenne-Twister" "Inversion"


It is possible to change the default generator to other PRNGs, such as Super-Duper,Wichmann-Hill, Marsaglia-Multicarry or even a user-supplied PRNG. See the ?RNGkind for further details. I have never needed to change the default PRNG.

The C GSL library also uses the Mersenne-Twister by default.

-
Are you sure about your second point, generating normal random variables by inverting the CDF? The inverse of the normal CDF is a fairly expensive function to evaluate. I imagine Box-Muller's method would be faster. Faster still would be Marsaglia's ziggurat method for generating normals. –  John D. Cook Aug 25 '10 at 14:53
I also find this suspicious. Marsaglia's Ziggurat is the default in Matlab, and I can't imagine Matlab being better than R in the field of random number generation. –  shabbychef Aug 25 '10 at 16:21
@John Indeed, the polar method is available in R, see the setRNG package. –  chl Aug 25 '10 at 21:28

The Mersenne Twister is one I've come across and used before now.

-
e.g., Python (j.mp/9TVyhv), Perl (j.mp/by85El), Octave (j.mp/aVQ5Xz), Clojure (j.mp/dkj9Z9, not the default one), Haskell (j.mp/aWK7kK), lua (j.mp/bSD2vO), or even SQL (j.mp/aOPJMW, for an overview) :-) –  chl Aug 25 '10 at 21:41