28int32_t
seed[4] = { 11111111, 22222222, 33333333, 44444444 };
39FindB(
long long a,
long long k,
long long m)
48 for(i = 1; i < 32; i++)
50 sqrs[i] =(sqrs[i - 1] * sqrs[i - 1]) % m;
55 for(i = 0; i < 32; i++)
63 power_of_2 = power_of_2 * 2;
81 int32_t R, S0, S1, q, qh, rh, k;
103 R =
H *(t - k * qh) - k * rh;
114 R -= k *(M - S1 * q);
117 R += S1 *(t - k * q);
122 R =
H *(R - k * qh) - k * rh;
130 R -= k *(M - S0 * q);
133 R += S0 *(t - k * q);
146#define S0_MAX 2147483646
147#define S1_MAX 2147483542
148#define S2_MAX 2147483422
149#define S3_MAX 2147483322
189 for(j = 0; j < 4; j++)
204 for(j = 0; j < 4; j++)
205 fprintf( f,
"%u ", g->
Cg[j]);
218 for(j = 0; j < 4; j++)
232 for(j = 0; j < 4; j++)
245 for(j = 0; j < 4; j++)
281 int positions = ((
sizeof(
tw_lpid)) * 8) - 1;
284 for(j = 0; j < 4; j++)
285 Ig_t[j] = the_rng->
seed[j];
287 mask_bit <<= positions;
295 for(j = 0; j < 4; j++)
297 avw_t[j] = the_rng->
avw[j];
300 for(i = 0; i < positions; i++)
301 avw_t[j] =
MultModM(avw_t[j], avw_t[j], the_rng->
m[j]);
303 Ig_t[j] =
MultModM(avw_t[j], Ig_t[j], the_rng->
m[j]);
309 }
while(positions > 0);
313 for(j = 0; j < 4; j++)
314 Ig_t[j] =
MultModM(the_rng->
avw[j], Ig_t[j], the_rng->
m[j]);
319 for(j = 0; j < 4; j++)
345 for(i = 0; i < nstreams; i++) {
350 for(j = 0; j < n_core_streams; j++) {
366 rng->m[0] = 2147483647;
367 rng->m[1] = 2147483543;
368 rng->m[2] = 2147483423;
369 rng->m[3] = 2147483323;
379 printf(
"Clamping Provided LP Seeds\n");
381 for(j = 0; j < 4; j++)
385 rng->seed[0] = 11111111;
386 rng->seed[1] = 22222222;
387 rng->seed[2] = 33333333;
388 rng->seed[3] = 44444444;
391 for(j = 0; j < 4; j++)
394 for(j = 0; j < 4; j++)
396 for(i = 1; i <= w; i++)
401 for(i = 1; i <= v; i++)
405 for(j = 0; j < 4; j++)
432 printf(
"Clamping Provided Core Seeds\n");
434 for(j = 0; j < 4; j++)
462 s = 45991 *(s - k * 46693) - k * 25884;
466 u = u + 4.65661287524579692e-10 * s;
470 s = 207707 *(s - k * 10339) - k * 870;
474 u = u - 4.65661310075985993e-10 * s;
480 s = 138556 *(s - k * 15499) - k * 3979;
484 u = u + 4.65661336096842131e-10 * s;
490 s = 49689 *(s - k * 43218) - k * 24121;
494 u = u - 4.65661357780891134e-10 * s;
517 long long *b =
rng->b;
530 s =(b[0] * s) % m[0];
532 u = u + 4.65661287524579692e-10 * s;
535 s =(b[1] * s) % m[1];
537 u = u - 4.65661310075985993e-10 * s;
542 s =(b[2] * s) % m[2];
544 u = u + 4.65661336096842131e-10 * s;
549 s =(b[3] * s) % m[3];
551 u = u - 4.65661357780891134e-10 * s;
void * tw_calloc(const char *file, int line, const char *for_who, size_t e_sz, size_t n)
void tw_error(const char *file, int line, const char *fmt,...)
unsigned int g_tw_nRNG_per_lp
unsigned int g_tw_nRNG_core_per_lp
tw_seed g_tw_core_rng_seed
void tw_rand_init_streams(tw_lp *lp, unsigned int nstreams, unsigned int n_core_streams)
tw_rng * rng_core_init(int v, int w)
tw_rng * rng_init(int v, int w)
double rng_gen_reverse_val(tw_rng_stream *g)
void rng_put_state(tw_rng_stream *g, uint32_t s[4])
void rng_get_state(tw_rng_stream *g, uint32_t s[4])
int32_t MultModM(int32_t s, int32_t t, int32_t M)
Returns(s*t) MOD M.
long long FindB(long long a, long long k, long long m)
Find B to run CLCG4 backwards.
void rng_write_state(tw_rng_stream *g, FILE *f)
void rng_set_seed(tw_rng_stream *g, uint32_t s[4], tw_rng *the_rng)
double rng_gen_val(tw_rng_stream *g)
void clamp_seed(uint32_t s[4])
void rng_init_generator(tw_rng_stream *g, SeedType Where, tw_rng *the_rng)
void tw_rand_initial_seed(tw_rng_stream *g, tw_lpid id, tw_rng *the_rng)
tw_rng_stream * rng
RNG stream array for this LP.
tw_rng_stream * core_rng
RNG stream array for ROSS non-model operation - possible alternative to a model_rng pointer array.