8 unsigned long MTRand_int32::state[n] = {0x0UL};
9 int MTRand_int32::p = 0;
10 bool MTRand_int32::init =
false;
12 void MTRand_int32::gen_state() {
13 for (
int i = 0; i < (n - m); ++i)
14 state[i] = state[i + m] ^ twiddle(state[i], state[i + 1]);
15 for (
int i = n - m; i < (n - 1); ++i)
16 state[i] = state[i + m - n] ^ twiddle(state[i], state[i + 1]);
17 state[n - 1] = state[m - 1] ^ twiddle(state[n - 1], state[0]);
21 void MTRand_int32::seed(
unsigned long s) {
22 state[0] = s & 0xFFFFFFFFUL;
23 for (
int i = 1; i < n; ++i) {
24 state[i] = 1812433253UL * (state[i - 1] ^ (state[i - 1] >> 30)) + i;
28 state[i] &= 0xFFFFFFFFUL;
33 void MTRand_int32::seed(
const unsigned long* array,
int size) {
36 for (
int k = ((n > size) ? n : size); k; --k) {
37 state[i] = (state[i] ^ ((state[i - 1] ^ (state[i - 1] >> 30)) * 1664525UL))
39 state[i] &= 0xFFFFFFFFUL;
41 if ((++i) == n) { state[0] = state[n - 1]; i = 1; }
43 for (
int k = n - 1; k; --k) {
44 state[i] = (state[i] ^ ((state[i - 1] ^ (state[i - 1] >> 30)) * 1566083941UL)) - i;
45 state[i] &= 0xFFFFFFFFUL;
46 if ((++i) == n) { state[0] = state[n - 1]; i = 1; }
48 state[0] = 0x80000000UL;