ROSS
rand-clcg4.c File Reference

RNG Implementation module. More...

#include <ross.h>

Go to the source code of this file.

Macros

#define H   32768
#define S0_MAX   2147483646
#define S1_MAX   2147483542
#define S2_MAX   2147483422
#define S3_MAX   2147483322

Functions

long long FindB (long long a, long long k, long long m)
 Find B to run CLCG4 backwards.
int32_t MultModM (int32_t s, int32_t t, int32_t M)
 Returns(s*t) MOD M.
void clamp_seed (uint32_t s[4])
void rng_set_seed (tw_rng_stream *g, uint32_t s[4], tw_rng *the_rng)
void rng_write_state (tw_rng_stream *g, FILE *f)
void rng_get_state (tw_rng_stream *g, uint32_t s[4])
void rng_put_state (tw_rng_stream *g, 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)
void tw_rand_init_streams (tw_lp *lp, unsigned int nstreams, unsigned int n_core_streams)
tw_rngrng_init (int v, int w)
tw_rngrng_core_init (int v, int w)
double rng_gen_val (tw_rng_stream *g)
double rng_gen_reverse_val (tw_rng_stream *g)

Variables

static tw_rngrng = NULL
static tw_rngcore_rng = NULL
int32_t seed [4] = { 11111111, 22222222, 33333333, 44444444 }

Detailed Description

Random number generator, provides all of the features GTW requires by default. Chris hacked this pretty well, he would know the features better.

Definition in file rand-clcg4.c.

Macro Definition Documentation

◆ H

#define H   32768

Definition at line 20 of file rand-clcg4.c.

Referenced by MultModM().

◆ S0_MAX

#define S0_MAX   2147483646

Definition at line 146 of file rand-clcg4.c.

Referenced by clamp_seed().

◆ S1_MAX

#define S1_MAX   2147483542

Definition at line 147 of file rand-clcg4.c.

Referenced by clamp_seed().

◆ S2_MAX

#define S2_MAX   2147483422

Definition at line 148 of file rand-clcg4.c.

Referenced by clamp_seed().

◆ S3_MAX

#define S3_MAX   2147483322

Definition at line 149 of file rand-clcg4.c.

Referenced by clamp_seed().

Function Documentation

◆ clamp_seed()

void clamp_seed ( uint32_t s[4])

These seeds MUST adhere to these requirements. This is explicitly stated in L'Ecuyer and Andres (1997)

Definition at line 155 of file rand-clcg4.c.

References S0_MAX, S1_MAX, S2_MAX, and S3_MAX.

Referenced by rng_core_init(), rng_init(), rng_set_seed(), and tw_rand_initial_seed().

◆ FindB()

long long FindB ( long long a,
long long k,
long long m )

FindB

B is $ a_[i]^{m_[i] - 2} \mathrm{mod m_[i]} $
which is used in running the CLCG4 backwards
Added by Chris Carothers, 5/15/98

Definition at line 39 of file rand-clcg4.c.

Referenced by rng_init().

◆ MultModM()

int32_t MultModM ( int32_t s,
int32_t t,
int32_t M )

MultiModM

See L'Ecuyer and Cote(1991).

Returns(s*t) MOD M. Assumes that -M < s < M and -M < t < M.

Definition at line 79 of file rand-clcg4.c.

References H.

Referenced by rng_init(), rng_init_generator(), and tw_rand_initial_seed().

◆ rng_core_init()

tw_rng * rng_core_init ( int v,
int w )

Definition at line 416 of file rand-clcg4.c.

References clamp_seed(), core_rng, g_tw_core_rng_seed, g_tw_mynode, rng, tw_calloc(), and TW_LOC.

Referenced by tw_rand_core_init().

◆ rng_gen_reverse_val()

double rng_gen_reverse_val ( tw_rng_stream * g)

Definition at line 515 of file rand-clcg4.c.

References tw_rng_stream::Cg, tw_rng_stream::count, rng, tw_error(), and TW_LOC.

◆ rng_gen_val()

double rng_gen_val ( tw_rng_stream * g)

Definition at line 451 of file rand-clcg4.c.

References tw_rng_stream::Cg, and tw_rng_stream::count.

◆ rng_get_state()

void rng_get_state ( tw_rng_stream * g,
uint32_t s[4] )

Definition at line 214 of file rand-clcg4.c.

References tw_rng_stream::Cg.

◆ rng_init()

tw_rng * rng_init ( int v,
int w )

Definition at line 359 of file rand-clcg4.c.

References clamp_seed(), FindB(), g_tw_mynode, g_tw_rng_seed, MultModM(), rng, tw_calloc(), and TW_LOC.

Referenced by tw_rand_init().

◆ rng_init_generator()

void rng_init_generator ( tw_rng_stream * g,
SeedType Where,
tw_rng * the_rng )

◆ rng_put_state()

void rng_put_state ( tw_rng_stream * g,
uint32_t s[4] )

Definition at line 228 of file rand-clcg4.c.

References tw_rng_stream::Cg.

◆ rng_set_seed()

void rng_set_seed ( tw_rng_stream * g,
uint32_t s[4],
tw_rng * the_rng )

Definition at line 183 of file rand-clcg4.c.

References clamp_seed(), tw_rng_stream::Ig, InitialSeed, and rng_init_generator().

◆ rng_write_state()

void rng_write_state ( tw_rng_stream * g,
FILE * f )

Definition at line 200 of file rand-clcg4.c.

References tw_rng_stream::Cg.

◆ tw_rand_init_streams()

void tw_rand_init_streams ( tw_lp * lp,
unsigned int nstreams,
unsigned int n_core_streams )

◆ tw_rand_initial_seed()

void tw_rand_initial_seed ( tw_rng_stream * g,
tw_lpid id,
tw_rng * the_rng )

Variable Documentation

◆ core_rng

tw_rng* core_rng = NULL
static

Definition at line 25 of file rand-clcg4.c.

Referenced by rng_core_init(), and tw_rand_init_streams().

◆ rng

tw_rng* rng = NULL
static

◆ seed

int32_t seed[4] = { 11111111, 22222222, 33333333, 44444444 }

Definition at line 28 of file rand-clcg4.c.