C++ Mersenne Twister Pseudo-Random Number Generator

On this page, I provide a C++ port of the famous Mersenne Twister pseudo-random number generator that has period 219937-1. The algorithm and original C source code are designed by

M. Matsumoto and T. Nishimura,
Mersenne Twister: A 623-Dimensionally Equidistributed
Uniform Pseudo-Random Number Generator
,
ACM Transactions on Modeling and Computer Simulation,
Vol. 8, No. 1, January 1998, pp. 3-30
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html.

I wrote a C++ port that takes advantage of the possibilities of the C++ programming language like inline member functions to enhance efficiency and the safety of classes. Probably because of this, the compiled code of this C++ version of the generator runs faster than the original C version, it runs even faster than the optimized C version written by Shawn Cokus (tested on a PC with Windows XP, a PC with Linux, and a Sun UltraSparc machine with Solaris, code was compiled with GNU C++ compiler and Borland C++ 5.5).

The code is ISO standard C++ and no additional libraries are needed.

Download mtrand.zip containing

mtreadme.txtreadme file
mtrand.hthe header file
mtrand.cppthe library file
mttest.cpptest program
mttest.outoutput of test program

The syntax highlighting is produced with C++2HTML.

© 2003 Jasper Bedaux