54 #define MATRIX_A 0x9908b0dfUL
55 #define UPPER_MASK 0x80000000UL
56 #define LOWER_MASK 0x7fffffffUL
58 static uint32_t mt[N];
62 void init_genrand(uint32_t s)
64 mt[0]= s & 0xffffffffUL;
65 for (mti=1; mti<N; mti++) {
67 (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
72 mt[mti] &= 0xffffffffUL;
81 void init_by_array(uint32_t init_key[],
int key_length)
84 init_genrand(19650218UL);
86 k = (N>key_length ? N : key_length);
88 mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
90 mt[i] &= 0xffffffffUL;
92 if (i>=N) { mt[0] = mt[N-1]; i=1; }
93 if (j>=key_length) j=0;
96 mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
98 mt[i] &= 0xffffffffUL;
100 if (i>=N) { mt[0] = mt[N-1]; i=1; }
103 mt[0] = 0x80000000UL;
107 uint32_t genrand_int32(
void)
110 static uint32_t mag01[2]={0x0UL, MATRIX_A};
117 init_genrand(5489UL);
119 for (kk=0;kk<N-M;kk++) {
120 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
121 mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
124 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
125 mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
127 y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
128 mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
137 y ^= (y << 7) & 0x9d2c5680UL;
138 y ^= (y << 15) & 0xefc60000UL;
145 int32_t genrand_int31(
void)
147 return (int32_t)(genrand_int32()>>1);
151 double genrand_real1(
void)
153 return genrand_int32()*(1.0/4294967295.0);
158 double genrand_real2(
void)
160 return genrand_int32()*(1.0/4294967296.0);
165 double genrand_real3(
void)
167 return (((
double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
172 double genrand_res53(
void)
174 uint32_t a=genrand_int32()>>5, b=genrand_int32()>>6;
175 return(a*67108864.0+b)*(1.0/9007199254740992.0);