MCPcopy Create free account
hub / github.com/numpy/numpy / rk_random

Function rk_random

numpy/random/src/mt19937/randomkit.c:216–245  ·  view source on GitHub ↗

* Slightly optimised reference implementation of the Mersenne Twister * Note that regardless of the precision of long, only 32 bit random * integers are produced */

Source from the content-addressed store, hash-verified

214 * integers are produced
215 */
216unsigned long rk_random(rk_state *state) {
217 unsigned long y;
218
219 if (state->pos == RK_STATE_LEN) {
220 int i;
221
222 for (i = 0; i < N - M; i++) {
223 y = (state->key[i] & UPPER_MASK) | (state->key[i + 1] & LOWER_MASK);
224 state->key[i] = state->key[i + M] ^ (y >> 1) ^ (-(y & 1) & MATRIX_A);
225 }
226 for (; i < N - 1; i++) {
227 y = (state->key[i] & UPPER_MASK) | (state->key[i + 1] & LOWER_MASK);
228 state->key[i] =
229 state->key[i + (M - N)] ^ (y >> 1) ^ (-(y & 1) & MATRIX_A);
230 }
231 y = (state->key[N - 1] & UPPER_MASK) | (state->key[0] & LOWER_MASK);
232 state->key[N - 1] = state->key[M - 1] ^ (y >> 1) ^ (-(y & 1) & MATRIX_A);
233
234 state->pos = 0;
235 }
236 y = state->key[state->pos++];
237
238 /* Tempering */
239 y ^= (y >> 11);
240 y ^= (y << 7) & 0x9d2c5680UL;
241 y ^= (y << 15) & 0xefc60000UL;
242 y ^= (y >> 18);
243
244 return y;
245}
246
247/*
248 * Returns an unsigned 64 bit random integer.

Callers 7

rk_uint64Function · 0.85
rk_uint32Function · 0.85
rk_ulongFunction · 0.85
rk_intervalFunction · 0.85
rk_doubleFunction · 0.85
rk_fillFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by 1

mainFunction · 0.68