From Jason Turner

[rand.eng.mers]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpsf5314yc/{from.md → to.md} +21 -11
tmp/tmpsf5314yc/{from.md → to.md} RENAMED
@@ -8,21 +8,31 @@ applied to X are to be taken modulo n.
8
 
9
  The transition algorithm employs a twisted generalized feedback shift
10
  register defined by shift values n and m, a twist value r, and a
11
  conditional xor-mask a. To improve the uniformity of the result, the
12
  bits of the raw shift register are additionally *tempered* (i.e.,
13
- scrambled) according to a bit-scrambling matrix defined by values
14
- u, d, s, b, t, c, and ℓ.
15
 
16
  The state transition is performed as follows:
17
 
 
 
 
 
 
18
  The sequence X is initialized with the help of an initialization
19
  multiplier f.
20
 
21
  The generation algorithm determines the unsigned integer values
22
  z₁, z₂, z₃, z₄ as follows, then delivers z₄ as its result:
23
 
 
 
 
 
 
24
  ``` cpp
25
  template<class UIntType, size_t w, size_t n, size_t m, size_t r,
26
  UIntType a, size_t u, UIntType d, size_t s,
27
  UIntType b, size_t t,
28
  UIntType c, size_t l, UIntType f>
@@ -48,11 +58,12 @@ template<class UIntType, size_t w, size_t n, size_t m, size_t r,
48
  static constexpr result_type min() { return 0; }
49
  static constexpr result_type max() { return 2^w - 1; }
50
  static constexpr result_type default_seed = 5489u;
51
 
52
  // constructors and seeding functions
53
- explicit mersenne_twister_engine(result_type value = default_seed);
 
54
  template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
55
  void seed(result_type value = default_seed);
56
  template<class Sseq> void seed(Sseq& q);
57
 
58
  // generating functions
@@ -66,18 +77,18 @@ The following relations shall hold: `0 < m`, `m <= n`, `2u < w`,
66
  `w <= numeric_limits<UIntType>::digits`, `a <= (1u<<w) - 1u`,
67
  `b <= (1u<<w) - 1u`, `c <= (1u<<w) - 1u`, `d <= (1u<<w) - 1u`, and
68
  `f <= (1u<<w) - 1u`.
69
 
70
  The textual representation of xᵢ consists of the values of
71
- Xᵢ₋ₙ, , Xᵢ₋₁, in that order.
72
 
73
  ``` cpp
74
- explicit mersenne_twister_engine(result_type value = default_seed);
75
  ```
76
 
77
- *Effects:* Constructs a `mersenne_twister_engine` object. Sets X₋ₙ to
78
- `value` mod 2ʷ. Then, iteratively for i = 1-n,…,-1, sets Xᵢ to $$%
79
  \bigl[f \cdot
80
  \bigl(X_{i-1} \xor \bigl(X_{i-1} \rightshift (w-2)\bigr)
81
  \bigr)
82
  + i \bmod n
83
  \bigr] \bmod 2^w
@@ -87,13 +98,12 @@ explicit mersenne_twister_engine(result_type value = default_seed);
87
 
88
  ``` cpp
89
  template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
90
  ```
91
 
92
- *Effects:* Constructs a `mersenne_twister_engine` object. With
93
- k = w / 32 ⌉ and a an array (or equivalent) of length n ⋅ k, invokes
94
- `q.generate(`a+0`, `a+n ⋅ k`)` and then, iteratively for i = -n,…,-1,
95
- sets Xᵢ to
96
  $\left(\sum_{j=0}^{k-1}a_{k(i+n)+j} \cdot 2^{32j} \right) \bmod 2^w$.
97
  Finally, if the most significant w-r bits of X₋ₙ are zero, and if each
98
  of the other resulting Xᵢ is 0, changes X₋ₙ to 2ʷ⁻¹.
99
 
 
8
 
9
  The transition algorithm employs a twisted generalized feedback shift
10
  register defined by shift values n and m, a twist value r, and a
11
  conditional xor-mask a. To improve the uniformity of the result, the
12
  bits of the raw shift register are additionally *tempered* (i.e.,
13
+ scrambled) according to a bit-scrambling matrix defined by values u, d,
14
+ s, b, t, c, and ℓ.
15
 
16
  The state transition is performed as follows:
17
 
18
+ - Concatenate the upper w-r bits of Xᵢ₋ₙ with the lower r bits of
19
+ $X_{i+1-n}$ to obtain an unsigned integer value Y.
20
+ - With $\alpha = a \cdot (Y \bitand 1)$, set Xᵢ to
21
+ $X_{i+m-n} \xor (Y \rightshift 1) \xor \alpha$.
22
+
23
  The sequence X is initialized with the help of an initialization
24
  multiplier f.
25
 
26
  The generation algorithm determines the unsigned integer values
27
  z₁, z₂, z₃, z₄ as follows, then delivers z₄ as its result:
28
 
29
+ - Let $z_1 = X_i \xor \bigl(( X_i \rightshift u ) \bitand d\bigr)$.
30
+ - Let $z_2 = z_1 \xor \bigl( (z_1 \leftshift{w} s) \bitand b \bigr)$.
31
+ - Let $z_3 = z_2 \xor \bigl( (z_2 \leftshift{w} t) \bitand c \bigr)$.
32
+ - Let $z_4 = z_3 \xor ( z_3 \rightshift \ell )$.
33
+
34
  ``` cpp
35
  template<class UIntType, size_t w, size_t n, size_t m, size_t r,
36
  UIntType a, size_t u, UIntType d, size_t s,
37
  UIntType b, size_t t,
38
  UIntType c, size_t l, UIntType f>
 
58
  static constexpr result_type min() { return 0; }
59
  static constexpr result_type max() { return 2^w - 1; }
60
  static constexpr result_type default_seed = 5489u;
61
 
62
  // constructors and seeding functions
63
+ mersenne_twister_engine() : mersenne_twister_engine(default_seed) {}
64
+ explicit mersenne_twister_engine(result_type value);
65
  template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
66
  void seed(result_type value = default_seed);
67
  template<class Sseq> void seed(Sseq& q);
68
 
69
  // generating functions
 
77
  `w <= numeric_limits<UIntType>::digits`, `a <= (1u<<w) - 1u`,
78
  `b <= (1u<<w) - 1u`, `c <= (1u<<w) - 1u`, `d <= (1u<<w) - 1u`, and
79
  `f <= (1u<<w) - 1u`.
80
 
81
  The textual representation of xᵢ consists of the values of
82
+ $X_{i - n}, \dotsc, X_{i - 1}$, in that order.
83
 
84
  ``` cpp
85
+ explicit mersenne_twister_engine(result_type value);
86
  ```
87
 
88
+ *Effects:* Sets X₋ₙ to `value` mod 2ʷ. Then, iteratively for
89
+ i = 1 - n, …, -1, sets Xᵢ to $$%
90
  \bigl[f \cdot
91
  \bigl(X_{i-1} \xor \bigl(X_{i-1} \rightshift (w-2)\bigr)
92
  \bigr)
93
  + i \bmod n
94
  \bigr] \bmod 2^w
 
98
 
99
  ``` cpp
100
  template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
101
  ```
102
 
103
+ *Effects:* With k = ⌈ w / 32 ⌉ and a an array (or equivalent) of length
104
+ n k, invokes `q.generate(`a+0`, `a+n ⋅ k`)` and then, iteratively for
105
+ i = -n,…,-1, sets Xᵢ to
 
106
  $\left(\sum_{j=0}^{k-1}a_{k(i+n)+j} \cdot 2^{32j} \right) \bmod 2^w$.
107
  Finally, if the most significant w-r bits of X₋ₙ are zero, and if each
108
  of the other resulting Xᵢ is 0, changes X₋ₙ to 2ʷ⁻¹.
109