Mt is a project mainly written in C and SHELL, it's free.
⇄ http://dev.ipol.im/git/nil/mt.git mirror (Mersenne Twister pseudo-random number generator)
% mt: Mersenne Twister pseudo-random number generator
mt.c contains the Mersenne Twister pseudo-random number generator, by Takuji Nishimura and Makoto Matsumoto (mt19937ar.c).
This geneator is fast and produces good pseudo-randomness. It has a very long period of 2^19937 − 1 and is k-distributed to 32-bit accuracy for every k in [1...623]. It passes rumerous tests for statistical randomness, including the Diehard tests.
This genreator provides better randomness than the default built-in ANSI C function rand(). Unlike the BSD/UNIX rand48() functions, this implementation is portable.
The original code has been slightly amended to keep only the core functions.
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
Like the original version, this code can be used for any purpose, includiong commercial use.
mt.c is ANSI C, and should compile on any system with any ANSI C compiler.
Compile mt.c with your program, and include mt.h to get the function declarations.
Initialize the random number generator with mt_init(). You can automatically initialize from the current time with mt_init_auto(). The automatic initialization will be better on POSIX systems (using milliseconds instead of seconds).
Get a random number in [0, 1) with 53 random bits (the maximum randomness for such number in double-precision) with mt_drand53().
This code is not thread-safe. You will not collect correct random values if it is called in a multi-thread context. For parallel code, use a reentrant implementation, like Pascal Getreuer's randmt: -> http://www.getreuer.info/home/randmt
see example/rand.c
Copyright 2010-2011 Nicolas Limare [email protected]
Copying and distribution of this README file, with or without modification, are permitted in any medium without royalty provided the copyright notice and this notice are preserved. This file is offered as-is, without any warranty.