Mersenne Twister with improved initialization

Japanese Version

News: we released SIMD-oriented Fast Mersenne Twister (SFMT). SFMT is roughly twice faster than the original Mersenne Twister, and has a better equidistibution property, as well as a quicker recovery from zero-excess initial state. Click here! (2007/1/31)

Among the all previous initialization routines of MT, there is a small problem that the most significant bit of the seed is not well reflected to the state vector.

We should have noticed this when an important caution on initializing tt800 (a small cousin of MT19937) was raised by Jeff Szuhay in the world-known random-number homepage pLab , or when Dick van Albada taught us that the older initialization scheme may yield just nearly "shifted" sequence. The both phenomena arise from the same problem, namely that if two initial states are too near with respect to the Hamming distance, then the corresponding output sequences are close to each other.

This type of defficiency becomes very clear by a report by Martin Kretschmar , who initialized the state vector with many zeroes, or some bit-pattern. Then the tendency of non-randomness remains for long.
Here putted is a new standard code of MT19937, mt19937ar.c (ar for ARray) solving this shortcoming. This code includes another initialization admitting an array of arbitrary length as a seed.
gzipped tar-file: mt19937ar.tgz .
This tar-ball includes
This version is free, in the sense that we adoped BSD license, which permits modifications and use in a commercial product.

Those who needs speed: all the five real-versions make a function call to the integer version genrand_int(), which makes them slower than the previous versions. If you maximize your compiler's optimization level, it often develops the function call into "inline". If it does not, and if you need speed, then copy the code of genrand_int into the necessary functions, and add by hand your requiring transformation from integer to real.

A possibly faster (depending on the platform) version considering Shawn Cokus's code is also available (2002/Feb./11). ( Agner Fog reported that Cokus's code is slower in Pentium 4) This is also freely usable.
gzipped tar-file of Cokus-type code with simplification and speed-up by Matthew Bellew: mt19937ar-cok.tgz .
This tar-ball includes Pablo M. Ronchi and other people suggested that it is useful to organize the original C code for mt19937ar into three source files: ordinary function file(.c), header file(.h) and test main file(.c). This would be more convenient for users.
gzipped tar-file of these files: mt19937ar.sep.tgz .
This tar-ball includes The generation/initialization algorithms are unchanged: same with the original mt19937ar.c (2002 version).

These versions are free, may be used for commercial use.
Return to MT's page