[READ-ONLY] Mirror of https://github.com/shuuji3/python-extension-twister. Experimental Python C extension to generate random numbers by using Mersenne twister
3.0 kB
79 lines
1This is a Mersenne Twister pseudorandom number generator
2with period 2^19937-1 with improved initialization scheme,
3modified on 2002/1/26 by Takuji Nishimura and Makoto Matsumoto.
4modified on 2005/4/26 by Mutsuo Saito
5
6Contents of this tar ball:
7readme-mt.txt this file
8mt19937ar.c the C source (ar: initialize by ARray)
9mt19937ar.h the C header file for mt19937ar
10mtTest.c the C test main program of mt19937ar.c
11mt19937ar.out Test outputs of six types generators. 1000 for each
12
131. Initialization
14 The initialization scheme for the previous versions of MT
15(e.g. 1999/10/28 version or earlier) has a tiny problem, that
16the most significant bits of the seed is not well reflected
17to the state vector of MT.
18
19This version (2002/1/26) has two initialization schemes:
20init_genrand(seed) and init_by_array(init_key, key_length).
21
22init_genrand(seed) initializes the state vector by using
23one unsigned 32-bit integer "seed", which may be zero.
24
25init_by_array(init_key, key_length) initializes the state vector
26by using an array init_key[] of unsigned 32-bit integers
27of length key_kength. If key_length is smaller than 624,
28then each array of 32-bit integers gives distinct initial
29state vector. This is useful if you want a larger seed space
30than 32-bit word.
31
322. Generation
33After initialization, the following type of pseudorandom numbers
34are available.
35
36genrand_int32() generates unsigned 32-bit integers.
37genrand_int31() generates unsigned 31-bit integers.
38genrand_real1() generates uniform real in [0,1] (32-bit resolution).
39genrand_real2() generates uniform real in [0,1) (32-bit resolution).
40genrand_real3() generates uniform real in (0,1) (32-bit resolution).
41genrand_res53() generates uniform real in [0,1) with 53-bit resolution.
42
43Note: the last five functions call the first one.
44if you need more speed for these five functions, you may
45suppress the function call by copying genrand_int32() and
46replacing the last return(), following to these five functions.
47
483. main()
49main() is an example to initialize with an array of length 4,
50then 1000 outputs of unsigned 32-bit integers,
51then 1000 outputs of real [0,1) numbers.
52
534. The outputs
54The output of the mt19937ar.c is in the file mt19937ar.out.
55If you revise or translate the code, check the output
56by using this file.
57
585. Cryptography
59This generator is not cryptoraphically secure.
60You need to use a one-way (or hash) function to obtain
61a secure random sequence.
62
636. Correspondence
64See:
65URL http://www.math.keio.ac.jp/matumoto/emt.html
66email matumoto@math.keio.ac.jp, nisimura@sci.kj.yamagata-u.ac.jp
67
687. Reference
69M. Matsumoto and T. Nishimura,
70"Mersenne Twister: A 623-Dimensionally Equidistributed Uniform
71Pseudo-Random Number Generator",
72ACM Transactions on Modeling and Computer Simulation,
73Vol. 8, No. 1, January 1998, pp 3--30.
74
75-------
76Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
77All rights reserved.
78Copyright (C) 2005, Mutsuo Saito
79All rights reserved.