User:Super mersenne/sandbox

The 64-bit Maximally Equidistributed F2-Linear Generator with Mersenne Prime Period (MELG-64) is a family of 64-bit Mersenne-Twister-type pseudorandom number generators developed by Shin Harase and Takamitsu Kimoto between 2014 and 2017, and the corresponding paper was published on ACM TOMS in 2018. MELG-64 has 64-bit very long period based on linear recurrences over the two-element field F2={0, 1} and is completely optimized in terms of the equidistribution properties with similar speed as 64-bit Mersenne Twisters.

Background
The 32-bit Mersenne Twister (MT) MT19937 is one of the most widely used pseudorandom number generator|pseudorandom number generators (PRNGs), but it is not completely optimized in terms of high-dimensional uniformity, which is a theoretical criterion of PRNGs. The 32-bit WELL generators was developed in order to overcome this weakness. As 64-bit PRNGs, MT19937-64 and SFMT19937 using SIMD were proposed, but there had existed no 64-bit MT-type PRNG completely optimized for high-dimensional uniformity.

Feature

 * Fast generation competitive with 64-bit Mersenne Twisters.
 * Very long period 219937-1 ≈ 106000.
 * This is the same period as widely used Mersenne Twisters.
 * Memory size requiring only 312 words (similarly to 64-bit Mersenne Twisters).
 * In accordance with memory size, implementations with various period lengths from 2607-1 to 244497-1 are provided.
 * High-dimensional uniformity completely optimized.
 * This property is one of the most informative criterion for high dimensional uniformity of PRNGs.
 * In the case of 32-bit PRNGs, WELL generators were known, but 64-bit counterparts had not been developed.
 * The non-zero coefficients of the characteristic polynomials drastically increased.
 * Approximately half of the coefficients of the characteristic polynomials are nonzero, and hence it is expected that MELG-64 recovers from 0-excess states very quickly.
 * The algorithm based on linear recurrence over the two-element field F2 and designed via several theoretical criteria.
 * The jump-ahead algorithm implemented in order to obtain disjoint streams in parallel computing. (The default skip size is 2256.)

High-dimensional uniformity
2-dimensionally_equidistribution_with_2-bit_accuracy.jpg

2-dimensionally_equidistribution_without_3-bit_accuracy.jpg

The high-dimensional uniformity is a theoretical criterion for PRNGs, which is assessed via the dimension of equidistribution with v-bit accuracy as follows.

Let
 * x0, x1, ..., xP-1, xP = x0, ...

be an unsigned w-bit binary integer sequence with period P, where w is the word size of the intended machine. Let truncv(xi) denote the number formed by the v most significant bits of xi. Consider the kv-bit vectors for the entire period:
 * (truncv(xi), truncv(xi+1), ..., truncv(xi+k-1)), &emsp; i = 0, ..., P-1.

A pseudorandom sequence xi of w-bit integers of period P is said to be k-dimensionally equidistributed with v-bit accuracy if each of the 2kv possible combinations of bits occurs the same number of times over the entire period P, except for the all-zero combination that occurs once less often.

The largest value of k with this property is called the ''dimension of equidistribution with v-bit accuracy'', denoted by k(v).

This definition is based on the assumption that the higher digits are large numbers. In particular, the dimension of equidistribution ensures that the output values with the v most significant bits are uniformly distributed up to dimension k(v). Thus, as a criterion of uniformity, larger values of k(v) for each 1 &le; v &le; w is desirable.

Now we have a trivial upper bound


 * k(v) &le; &lfloor; log2(P+1) / v &rfloor;

for each v = 1, 2, ...,w. Define the sum of the gaps


 * &Delta; := &sum; &ensp; &lfloor; log2(P+1) / v &rfloor; - k(v)),

where the sum is over all 1 &le; v &le; w.

If &Delta; = 0, the generator is said to be maximally equidistributed (ME).

Performance
The following table summarizes the CPU time (in seconds) taken to generate 109 64-bit unsigned integers and the figures of merit &Delta; and N1. Here, N1 is the number of nonzero coefficients of the characteristic polynomial and N1 should be in the vicinity of the half of 19937.

Platforms (64-bit CPUs and OSs):
 * CPU time (Intel): Intel Core i7-3770 (3.40GHz) Linux gcc compiler with -O3
 * CPU time (AMD): AMD Phenom II X6 1045T (2.70 GHz) Linux gcc compiler with -O3