next state generating function */
| 21 | |
| 22 | /* next state generating function */ |
| 23 | void gen_next(mt19937_state *state) { |
| 24 | int num; |
| 25 | unsigned long y; |
| 26 | static unsigned long mag02[2] = {0x0ul, MATRIX_A}; |
| 27 | |
| 28 | num = state->pos; |
| 29 | if (num < N - M) { |
| 30 | y = (state->key[num] & UPPER_MASK) | (state->key[num + 1] & LOWER_MASK); |
| 31 | state->key[num] = state->key[num + M] ^ (y >> 1) ^ mag02[y % 2]; |
| 32 | state->pos++; |
| 33 | } else if (num < N - 1) { |
| 34 | y = (state->key[num] & UPPER_MASK) | (state->key[num + 1] & LOWER_MASK); |
| 35 | state->key[num] = state->key[num + (M - N)] ^ (y >> 1) ^ mag02[y % 2]; |
| 36 | state->pos++; |
| 37 | } else if (num == N - 1) { |
| 38 | y = (state->key[N - 1] & UPPER_MASK) | (state->key[0] & LOWER_MASK); |
| 39 | state->key[N - 1] = state->key[M - 1] ^ (y >> 1) ^ mag02[y % 2]; |
| 40 | state->pos = 0; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | void add_state(mt19937_state *state1, mt19937_state *state2) { |
| 45 | int i, pt1 = state1->pos, pt2 = state2->pos; |