Some of Mersenne Twister
认识一下马特赛特旋转演算法
Mersenne Twister算法是一个伪随机数发生器(PRNG),其主要作用是生成伪随机数,它是目前为止应用最广泛的伪随机生成器,此算法的名字起于周期长度通常取Mersenne质数这样一个事实。马特赛特旋转演算法是Makoto Matsumoto (松本)和Takuji Nishimura (西村)于1997年开发的,基于有限二进制字段上的矩阵线性再生。可以快速产生高质量的伪随机数,修正了古老随机数产生算法的很多缺陷。最普遍使用的此算法版本是基于梅森质数219937−1,它的标准继承MT19937使用32位字长;此外还存在另一种使用64位字长的继承算法MT19937-64,它产生完全不同的序列。
The Mersenne Twister is a pseudorandom number generator (PRNG). It is by far the most widely used general-purpose PRNG.[1] Its name derives from the fact that its period length is chosen to be a Mersenne prime.
The Mersenne Twister was developed in 1997 by Makoto Matsumoto (ja) (松本 眞) and Takuji Nishimura (西村 拓士).[2] It was designed specifically to rectify most of the flaws found in older PRNGs. It was the first PRNG to provide fast generation of high-quality pseudorandom integers.
The most commonly used version of the Mersenne Twister algorithm is based on the Mersenne prime 219937−1. The standard implementation of that, MT19937, uses a 32-bit word length. There is another implementation that uses a 64-bit word length, MT19937-64; it generates a different sequence.
Adoption in software systems
软件系统中的使用
The Mersenne Twister is the default PRNG for the following software systems:
在以下系统中马特赛特演算法是默认的伪随机数发生器:
Microsoft Visual C++,[3] Microsoft Excel,[4] GAUSS,[5] GLib,[6] GNU Multiple Precision Arithmetic Library,[7] GNU Octave,[8] GNU Scientific Library,[9] gretl,[10] IDL,[11] Julia,[12] CMU Common Lisp,[13] Embeddable Common Lisp,[14] Steel Bank Common Lisp,[15] Maple,[16] MATLAB,[17] Free Pascal,[18] PHP,[19] Python,[20][21] R,[22] Ruby,[23] SageMath,[24] Scilab,[25] Stata.[26] It is also available in Apache Commons,[27] in standard C++ (since C++11),[28][29] and in Mathematica.[30] Add-on implementations are provided in many program libraries, including the Boost C++ Libraries,[31] the CUDA Library,[32] and the NAG Numerical Library.[33]
马特赛特旋转演算法是SPSS中伪随机生成器之一:另外一种生成器只对旧的程序保持兼容性,相对的马特赛特算法被认为更加可行。马特赛特算法也与SAS中的一个伪随机生成器类似,但是另外一个被认为很老旧而且已经不被赞成使用。
The Mersenne Twister is one of two PRNGs in SPSS: the other generator is kept only for compatibility with older programs, and the Mersenne Twister is stated to be "more reliable".[34] The Mersenne Twister is similarly one of the PRNGs in SAS: the other generators are older and deprecated.[35]
Advantages
优点
The commonly used version of Mersenne Twister, MT19937, which produces a sequence of 32-bit integers, has the following desirable properties:
使用广泛的马特赛特算法MT19937会产生一个32位整数序列,它拥有以下令人满意的特性:
It has a very long period of 219937 − 1. While a long period is not a guarantee of quality in a random number generator, short periods (such as the 232 common in many older software packages) can be problematic.[36]
马特赛特算法拥有非常长的219937 − 1周期,尽管龙周期并不是随机数字生成的保证,但是短周期(比如在许多旧的软件包中使用的通用232算法)问题更多。
It is k-distributed to 32-bit accuracy for every 1 ≤ k ≤ 623 (请看下面的定义).
对于1 ≤ k ≤ 623它是很精确的32位K分布。
It passes numerous tests for statistical randomness, including the Diehard tests.
它为统计随机性传递很多的测试,包括极端顽固测试
Disadvantages
缺点
The large state space comes with a performance cost: the 2.5 KiB state buffer will place a load on the memory caches. In 2011, Saito & Matsumoto proposed a version of the Mersenne Twister to address this issue. The tiny version, TinyMT, uses just 127 bits of state space.[37]
By today's standards, the Mersenne Twister is somewhat slow, [38] unless the SFMT implementation is used (see section below).
It passes most, but not all, of the stringent TestU01 randomness tests.[39] Because it is based on simple linear (xor) operations, it fails tests based on linear complexity after relatively few bits of output, despite its extremely large state.[citation needed] Passing the output through a simple hash function can remedy this weakness.
Multiple Mersenne Twister instances that differ only in seed value (but not other parameters) are not generally appropriate for Monte-Carlo simulations that require independent random number generators, though there exists a method for choosing multiple sets of parameter values.[40][41]
It can take a long time to start generating output that passes randomness tests, if the initial state is highly non-random