49 #define MATRIX_A 0x9908b0dfUL
50 #define UPPER_MASK 0x80000000UL
51 #define LOWER_MASK 0x7fffffffUL
53 static unsigned long mt[N];
60 void init_genrand(
unsigned long s)
62 mt[0]= s & 0xffffffffUL;
63 for (mti=1; mti<N; mti++) {
65 (1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
70 mt[mti] &= 0xffffffffUL;
78 void init_by_array(
unsigned long init_key[],
int key_length)
81 init_genrand(19650218UL);
83 k = (N>key_length ? N : key_length);
85 mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
87 mt[i] &= 0xffffffffUL;
89 if (i>=N) { mt[0] = mt[N-1]; i=1; }
90 if (j>=key_length) j=0;
93 mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
95 mt[i] &= 0xffffffffUL;
97 if (i>=N) { mt[0] = mt[N-1]; i=1; }
100 mt[0] = 0x80000000UL;
104 unsigned long genrand_int32(
void)
107 static unsigned long mag01[2]={0x0UL, MATRIX_A};
114 init_genrand(5489UL);
116 for (kk=0;kk<N-M;kk++) {
117 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
118 mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
121 y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
122 mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
124 y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
125 mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
134 y ^= (y << 7) & 0x9d2c5680UL;
135 y ^= (y << 15) & 0xefc60000UL;
142 long genrand_int31(
void)
144 return (
long)(genrand_int32()>>1);
148 double genrand_real1(
void)
150 return genrand_int32()*(1.0/4294967295.0);
155 double genrand_real2(
void)
157 return genrand_int32()*(1.0/4294967296.0);
162 double genrand_real3(
void)
164 return (((
double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
169 double genrand_res53(
void)
171 unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
172 return(a*67108864.0+b)*(1.0/9007199254740992.0);
Namespace for the standard utility objects.