Some Uniform and Normal Random Number Generators


xorgens is a collection of uniform random number generators written in C and returning 32 or 64-bit integer or real values. The generators use a generalisation of Marsaglia's "xorshift" random number generators [218, 224]. They are fast, appear to be good, and have periods greater than 101200.

The source code of version 3.06 is available here (xorgens306.tar.gz) and here ( The theory is described in my paper [224]. The only difference between versions 3.04, 3.05 and 3.06 are a small correction to the comments regarding the constant weyl (thanks to G. Weijers for this) and a change in some declarations from int to unsigned int to avoid a compiler warning about comparison of signed and unsigned integers.

xorgens has been tested using various statistical tests and appears to be satisfactory. However, we recommend that you do your own tests.

If you want to experiment with different sets of parameters, a short table of possibilities is available here (xortable.txt, 2K). Note that the code assumes that r is a power of two, so some small changes are required if this is not the case. We do not recommend the generators with n < 256 because their state space is too small.

xorgens is available (free, but with absolutely no warranty) as open-source software under the GNU General Public License.


ranut is a uniform pseudo-random number generator which uses recurrences based on primitive trinomials, or in some cases trinomials which have large primitive factors (over the field GF(2)). It is written in Fortran 77 and is optimised to run efficiently on vector processors, but also works well on other machines with IEEE Standard 64-bit floating-point arithmetic. The recurrences are implemented directly in floating-point to generate real numbers in [0,1], rather than integers.

ranut has been tested using George Marsaglia's Diehard package and appears to be satisfactory. However, we recommend that you do your own tests and, if necessary, combine the output of ranut with that of an independent random number generator.

ranut is based on an earlier generator RANU4 (1991) which is described in [132].

Note that ranut and RANU4 implemented the "fast jump ahead" idea (using arithmetic modulo the generating polynomial) which was recently rediscovered by Haramoto, Matsumoto, Nishimura, Panneton and L'Ecuyer [INFORMS Journal on Computing 20, 3, Summer 2008, 385-390, DOI: 10.1287/ijoc.1070.0251]. The implementation in RANU4 was described in [Sec. 8, 132].

Nowadays I prefer xorgens to ranut since generators based on primitive trinomials have some theoretical weaknesses. However, the trinomials used in ranut have such high degree that these weaknesses are probably insignificant in practice.


rannw is a Fortran 77 pseudo-random number generator which uses a variant of Chris Wallace's method to generate normally distributed (i.e. Gaussian) numbers.

Most algorithms for generating normally distributed random numbers are slow because they first generate uniformly distributed numbers and then transform them to normally distributed numbers. rannw is potentially faster because it generates normally distributed numbers directly, without using uniformly distributed numbers (except occasionally, for initialisation etc).

rannw has been tested using Marsaglia's Diehard package and appears to be satisfactory. (Because Diehard is designed to test uniformly distributed numbers, the output of rannw was transformed appropriately before input to Diehard.)

rannw is based on an earlier generator RANN4 which is described in [170, 185].

Wallace's own implementation of his method (written in C) is available here.

Availability - the random package

ranut and rannw are available in the random package (free, but with absolutely no warranty) as open-source software under the GNU General Public License.

A gzipped tar file of random version 1.03 is available here (48 KB). There is also a zip file (55 KB). The distribution contains the Fortran source code, test programs, output obtained from testing with Diehard, etc.

Return to Richard Brent's index page