The Mersenne Twist method for generating pseudorandom numbers is an extremely fast, flexible, and desirable approach to random-number generation. It has superb statistical properties and a ridiculously long period (2^19937-1).

A number of implementations of the MT PRNG exist, in a number of languages. Most of these are listed on the inventors' Web page. However, I wanted something a bit more flexible and complete than was available; in particular I wanted multiple independent PRN streams. In the process of writing that code, I got involved in a bit of optimization and wound up with a faster implementation than anything else available at the time. My version can be downloaded in source form for use under the LGPL.

My PRNG package will generate numbers in both integer and floating-point format, including 64-bit integers if the compiler supports them. It also supports the ability to generate multiple independent streams of random numbers, so that simulations and similar studies can be done without inadvertent correlations.

In addition to the PRNG code, my package also includes code to generate random variates following a number of common distributions (uniform, normal, lognormal, exponential, Erlang, Weibull, triangular, and empirical).

Finally, my package follows two ideas from Richard J. Wagner.
First, it is simple to initialize the PRNG from the system time or
from `/dev/random`

(when available. This feature is very
handy for games, signature pickers, and similar applications that need
to get a different random-number stream each time they are run.
Second, the PRNG state can be saved to a file (in ASCII) and restored
later. The save format is compatible with Wagner's code.

Running in 32-bit mode on the fastest machine available to me at the time, a 3.6 GHz Pentium Xeon, my PRNG can produce up to 132 million random 32-bit integers per second, and 59.1 million 64-bit integers per second. Floating-point values are slower, of course: about 36.3 million per second for numbers with 32 bits of randomness, and 18.9 million per second for 53 bits of randomness (which is the maximum representable on most machines). These figures are the result of ten experimental runs with the same random seed, and are valid to the given precision at a 99% confidence level.

On an older 450 MHz Pentium II, my implementation generates up to 21.2 million random 32-bit integers per second, and 8.2 million 64-bit integers per second. Floating-point values are generated at about 11.3 million per second for numbers with 32 bits of randomness, and 5.3 million per second for 53 bits of randomness.

The current version of the package is 1.5. Because of the provenance of the code, most of it is released under the LGPL. The source is available for download in gzipped tar format only.

Please report bugs and requests for improvements to the author of the package.

This web page is maintained by Geoff Kuenning.