easyRNG
1.2
BSD licensed random number generators for C and Fortran
|
The random number generator API. More...
Data Structures | |
struct | easy_rng_type |
Typedefs | |
typedef struct _easy_rng | easy_rng |
Functions | |
easy_rng * | easy_rng_alloc (const easy_rng_type *T) |
void | easy_rng_set (const easy_rng *r, unsigned long int s) |
void | easy_rng_free (easy_rng *r) |
unsigned long int | easy_rng_get (const easy_rng *r) |
double | easy_rng_uniform (const easy_rng *r) |
double | easy_rng_uniform_pos (const easy_rng *r) |
unsigned long int | easy_rng_uniform_int (const easy_rng *r, unsigned long int n) |
const char * | easy_rng_name (const easy_rng *r) |
unsigned long int | easy_rng_max (const easy_rng *r) |
unsigned long int | easy_rng_min (const easy_rng *r) |
const easy_rng_type ** | easy_rng_types_setup (void) |
const easy_rng_type * | easy_rng_env_setup (void) |
int | easy_rng_memcpy (easy_rng *dest, const easy_rng *src) |
easy_rng * | easy_rng_clone (const easy_rng *r) |
int | easy_rng_equal (const easy_rng *ra, const easy_rng *rb) |
int | easy_rng_fwrite (FILE *stream, const easy_rng *r) |
int | easy_rng_fread (FILE *stream, easy_rng *r) |
Variables | |
const easy_rng_type * | easy_rng_minstd_rand0 |
const easy_rng_type * | easy_rng_minstd_rand |
const easy_rng_type * | easy_rng_mt19937 |
const easy_rng_type * | easy_rng_mt19937_64 |
const easy_rng_type * | easy_rng_ranlux24_base |
const easy_rng_type * | easy_rng_ranlux48_base |
const easy_rng_type * | easy_rng_ranlux24 |
const easy_rng_type * | easy_rng_ranlux48 |
const easy_rng_type * | easy_rng_knuth_b |
const easy_rng_type * | easy_rng_default |
unsigned long int | easy_rng_default_seed |
The random number generator API.
This header contains all functions and definitions that are necessary to instantiate a random number generator, as well as to obtain uniformly distributed random numbers. The API is strongly modelled after the GNU Scientific Library's gsl_rng.h header, with some notable exceptions:
struct easy_rng_type |
A struct whose instances represent the different types of random number generators that are offered by easyRNG
There is never a need to instantiate this class yourself. Instead use the global variables to pass to easy_rng_alloc() when constructing a random number generator.
typedef struct _easy_rng easy_rng |
A random number generator instance
Pointers to these instances are returned by easy_rng_alloc() and should be freed with easy_rng_free(). Its contents are intentionally not accessible.
easy_rng* easy_rng_alloc | ( | const easy_rng_type * | T | ) |
Create a new random number generator instance
T | The type of a random number generator to use |
void easy_rng_set | ( | const easy_rng * | r, |
unsigned long int | s | ||
) |
Set the current seed.
Changes the current seed of the random number generator to s. This will change the generated sequence from this point onwards.
r | The random number generator instance |
s | The new seed |
void easy_rng_free | ( | easy_rng * | r | ) |
Frees the memory associated with a random number generator instance
After calling this function, do not attempt to pass the random number generator instance to any other function!
r | The random number generator instance |
unsigned long int easy_rng_get | ( | const easy_rng * | r | ) |
Generate a random, uniformally distributed unsigned long int.
This value will be within the interval defined by easy_rng_min() and easy_rng_max().
r | The random number generator instance |
double easy_rng_uniform | ( | const easy_rng * | r | ) |
Generate a random, uniformally distributed double precision floating point number in the interval [0,1)
This interval includes 0, but excludes 1
r | The random number generator instance |
double easy_rng_uniform_pos | ( | const easy_rng * | r | ) |
Generate a random, uniformally distributed double precision floating point number in the interval (0,1)
This interval excludes both 0 and 1
r | The random number generator instance |
unsigned long int easy_rng_uniform_int | ( | const easy_rng * | r, |
unsigned long int | n | ||
) |
Generate a random, uniformally distributed unsigned long int in the interval [0, n)
This interval includes 0, but excluded n, so the highest possibly generated value is n-1
r | The random number generator instance |
n | The upper limit (exclusive) of the generated values |
const char* easy_rng_name | ( | const easy_rng * | r | ) |
Return the name of the random generator type as string
Do not attempt to free the string!
r | The random number generator instance |
unsigned long int easy_rng_max | ( | const easy_rng * | r | ) |
Return the maximum value that can be returned by easy_rng_get()
This value depends on the random number generator type that was used to initialize the random number generator instance with easy_rng_alloc().
r | The random number generator instance |
unsigned long int easy_rng_min | ( | const easy_rng * | r | ) |
Return the minimum value that can be returned by easy_rng_get()
This value depends on the random number generator type that was used to initialize the random number generator instance with easy_rng_alloc().
r | The random number generator instance |
const easy_rng_type** easy_rng_types_setup | ( | void | ) |
Return a NULL terminated array with all available random number generator types
This array must not be freed!
const easy_rng_type* easy_rng_env_setup | ( | void | ) |
Set the default seed and/or default random number generator type
This method parses the environment variables EASY_RNG_TYPE
and EASY_RNG_SEED
to extract resp. the random number generator type and seed that will be used when using easy_rng_alloc() with easy_rng_default to instantiate and seed a new random number generator.
Copy the state of a random number generator src
into another random number generator dest
Afterwards, src
and dest
will produce identical sequences of random numbers. dest
must have been allocated with the exact same random number generator src!
dest | The destination random number generator |
src | The source random number generator |
Creates an exact copy of the random number generator c
.
c
and its freshly created clone will produce identical sequences of random numbers from now onwards. Free the clone using easy_rng_free().
r | The random number generator instance |
Test if two random number generator instances are identical
This test will verify both type and state for equality.
ra | The first random number generator instance |
rb | The second random number generator instance |
int easy_rng_fwrite | ( | FILE * | stream, |
const easy_rng * | r | ||
) |
Write the state of the random number generator to a file
This writes only the state, not the type of the generator!
stream | Filehandle to write the state to |
r | The random number generator instance |
int easy_rng_fread | ( | FILE * | stream, |
easy_rng * | r | ||
) |
Read the state of the random number generator from a file
This reads only the state, not the type of the generator!
stream | Filehandle to read the state from |
r | The random number generator instance |
const easy_rng_type* easy_rng_minstd_rand0 |
Linear congruential engine, discovered in 1969 by Lewis, Goodman and Miller, adopted as "Minimal standard" in 1988 by Park and Miller
const easy_rng_type* easy_rng_minstd_rand |
Linear congruential engine, newer "Minimum standard", recommended by Park, Miller, and Stockmeyer in 1993
const easy_rng_type* easy_rng_mt19937 |
32-bit Mersenne Twister engine, published by Matsumoto and Nishimura, 1998
This is also the type that easy_rng_default maps to, unless overridden by EASY_RNG_TYPE and easy_rng_env_setup() is called. In case of doubt, always use this type.
const easy_rng_type* easy_rng_mt19937_64 |
64-bit Mersenne Twister engine, published by Matsumoto and Nishimura, 2000
const easy_rng_type* easy_rng_ranlux24_base |
A subtract with carry engine
const easy_rng_type* easy_rng_ranlux48_base |
A subtract with carry engine
const easy_rng_type* easy_rng_ranlux24 |
A subtract with carry engine, that discards a certain amount of data produced by the base engine.
const easy_rng_type* easy_rng_ranlux48 |
A subtract with carry engine, that discards a certain amount of data produced by the base engine.
const easy_rng_type* easy_rng_knuth_b |
A shuffle order engine
const easy_rng_type* easy_rng_default |
The default random number generator type
Maps by default to easy_rng_mt19937
unsigned long int easy_rng_default_seed |
The seed that will be used to initialize newly allocated random number generators