54 #define MATRIX_A 0x9908b0dfUL
55 #define UMASK 0x80000000UL
56 #define LMASK 0x7fffffffUL
57 #define MIXBITS(u,v) ( ((u) & UMASK) | ((v) & LMASK) )
58 #define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))
63 static unsigned long *
next;
68 state[0]= s & 0xffffffffUL;
75 state[j] &= 0xffffffffUL;
88 k = (
N>key_length ?
N : key_length);
92 state[i] &= 0xffffffffUL;
95 if (j>=key_length) j=0;
100 state[i] &= 0xffffffffUL;
105 state[0] = 0x80000000UL;
110 unsigned long *p=
state;
120 for (j=
N-
M+1; --j; p++) {
123 *p = p[
M] ^
TWIST(p[0], p[1]);
126 for (j=
M; --j; p++) {
129 *p = p[
M-
N] ^
TWIST(p[0], p[1]);
146 y ^= (y << 7) & 0x9d2c5680UL;
147 y ^= (y << 15) & 0xefc60000UL;
156 return(a*67108864.0+b)*(1.0/9007199254740992.0);
PN potion_rand(Potion *P, PN cl, PN self)
void init_genrand(unsigned long s)
unsigned long potion_rand_int(void)
generates a random number on [0,0xffffffff]-interval
PN potion_num_rand(Potion *P, PN cl, PN self)
void init_by_array(unsigned long init_key[], int key_length)
double potion_rand_double(void)
generates a random number on [0,1) with 53-bit resolution
static unsigned long state[N]
the global interpreter state P. currently singleton (not threads yet)
static unsigned long * next
PN potion_srand(Potion *P, PN cl, PN self, PN seed)
static void next_state(void)