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

Function mt19937_init_by_array

numpy/random/src/mt19937/mt19937.c:42–80  ·  view source on GitHub ↗

* initialize by an array with array-length * init_key is the array for initializing keys * key_length is its length */

Source from the content-addressed store, hash-verified

40 * key_length is its length
41 */
42void mt19937_init_by_array(mt19937_state *state, uint32_t *init_key,
43 int key_length) {
44 /* was signed in the original code. RDH 12/16/2002 */
45 int i = 1;
46 int j = 0;
47 uint32_t *mt = state->key;
48 int k;
49
50 init_genrand(state, 19650218UL);
51 k = (RK_STATE_LEN > key_length ? RK_STATE_LEN : key_length);
52 for (; k; k--) {
53 /* non linear */
54 mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1664525UL)) +
55 init_key[j] + j;
56 /* for > 32 bit machines */
57 mt[i] &= 0xffffffffUL;
58 i++;
59 j++;
60 if (i >= RK_STATE_LEN) {
61 mt[0] = mt[RK_STATE_LEN - 1];
62 i = 1;
63 }
64 if (j >= key_length) {
65 j = 0;
66 }
67 }
68 for (k = RK_STATE_LEN - 1; k; k--) {
69 mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1566083941UL)) -
70 i; /* non linear */
71 mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
72 i++;
73 if (i >= RK_STATE_LEN) {
74 mt[0] = mt[RK_STATE_LEN - 1];
75 i = 1;
76 }
77 }
78
79 mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
80}
81
82void mt19937_gen(mt19937_state *state) {
83 uint32_t y;

Callers

nothing calls this directly

Calls 1

init_genrandFunction · 0.85

Tested by

no test coverage detected