26 int32_t
seed[4] = { 11111111, 22222222, 33333333, 44444444 };
37 FindB(
long long a,
long long k,
long long m)
46 for(i = 1; i < 32; i++)
48 sqrs[i] =(sqrs[i - 1] * sqrs[i - 1]) % m;
53 for(i = 0; i < 32; i++)
61 power_of_2 = power_of_2 * 2;
79 int32_t R, S0, S1, q, qh, rh, k;
101 R =
H *(t - k * qh) - k * rh;
112 R -= k *(M - S1 * q);
115 R += S1 *(t - k * q);
120 R =
H *(R - k * qh) - k * rh;
128 R -= k *(M - S0 * q);
131 R += S0 *(t - k * q);
144 #define S0_MAX 2147483646
145 #define S1_MAX 2147483542
146 #define S2_MAX 2147483422
147 #define S3_MAX 2147483322
187 for(j = 0; j < 4; j++)
202 for(j = 0; j < 4; j++)
203 fprintf( f,
"%u ", g->
Cg[j]);
216 for(j = 0; j < 4; j++)
230 for(j = 0; j < 4; j++)
243 for(j = 0; j < 4; j++)
274 int positions = ((
sizeof(
tw_lpid)) * 8) - 1;
277 for(j = 0; j < 4; j++)
278 Ig_t[j] = rng->
seed[j];
280 mask_bit <<= positions;
288 for(j = 0; j < 4; j++)
290 avw_t[j] = rng->
avw[j];
293 for(i = 0; i < positions; i++)
294 avw_t[j] =
MultModM(avw_t[j], avw_t[j], rng->
m[j]);
296 Ig_t[j] =
MultModM(avw_t[j], Ig_t[j], rng->
m[j]);
302 }
while(positions > 0);
306 for(j = 0; j < 4; j++)
312 for(j = 0; j < 4; j++)
329 for(i = 0; i < nstreams; i++) {
345 rng->
m[0] = 2147483647;
346 rng->
m[1] = 2147483543;
347 rng->
m[2] = 2147483423;
348 rng->
m[3] = 2147483323;
358 for(j = 0; j < 4; j++)
362 rng->
seed[0] = 11111111;
363 rng->
seed[1] = 22222222;
364 rng->
seed[2] = 33333333;
365 rng->
seed[3] = 44444444;
368 for(j = 0; j < 4; j++)
369 rng->
aw[j] = rng->
a[j];
371 for(j = 0; j < 4; j++)
373 for(i = 1; i <= w; i++)
376 rng->
avw[j] = rng->
aw[j];
378 for(i = 1; i <= v; i++)
382 for(j = 0; j < 4; j++)
383 rng->
b[j] =
FindB(rng->
a[j],(rng->
m[j] - 2), rng->
m[j]);
403 s = 45991 *(s - k * 46693) - k * 25884;
407 u = u + 4.65661287524579692e-10 * s;
411 s = 207707 *(s - k * 10339) - k * 870;
415 u = u - 4.65661310075985993e-10 * s;
421 s = 138556 *(s - k * 15499) - k * 3979;
425 u = u + 4.65661336096842131e-10 * s;
431 s = 49689 *(s - k * 43218) - k * 24121;
435 u = u - 4.65661357780891134e-10 * s;
453 long long *b = rng->
b;
466 s =(b[0] * s) % m[0];
468 u = u + 4.65661287524579692e-10 * s;
471 s =(b[1] * s) % m[1];
473 u = u - 4.65661310075985993e-10 * s;
478 s =(b[2] * s) % m[2];
480 u = u + 4.65661336096842131e-10 * s;
485 s =(b[3] * s) % m[3];
487 u = u - 4.65661357780891134e-10 * s;
void clamp_seed(uint32_t s[4])
tw_rng * rng_init(int v, int w)
void tw_error(const char *file, int line, const char *fmt,...) NORETURN
int32_t MultModM(int32_t s, int32_t t, int32_t M)
Returns(s*t) MOD M.
double rng_gen_val(tw_rng_stream *g)
void rng_write_state(tw_rng_stream *g, FILE *f)
void tw_rand_initial_seed(tw_rng_stream *g, tw_lpid id)
void rng_get_state(tw_rng_stream *g, uint32_t s[4])
unsigned int g_tw_nRNG_per_lp
void rng_init_generator(tw_rng_stream *g, SeedType Where)
void rng_set_seed(tw_rng_stream *g, uint32_t s[4])
void rng_put_state(tw_rng_stream *g, uint32_t s[4])
double rng_gen_reverse_val(tw_rng_stream *g)
tw_rng_stream * rng
RNG stream array for this LP.
void tw_rand_init_streams(tw_lp *lp, unsigned int nstreams)
long long FindB(long long a, long long k, long long m)
Find B to run CLCG4 backwards.
void * tw_calloc(const char *file, int line, const char *for_who, size_t e_sz, size_t n)