randomWH API
Generation of Pseudo-Random Variates
|
Typedef
of struct
to store and process the four generator seeds.
More...
#include <randomWH.h>
Data Fields | |
Variables | |
long int | x |
long int | y |
long int | z |
long int | t |
enum BOOLEAN | initialised |
Member Functions | |
void(* | init )(struct generator *self, long int x, long int y, long int z, long int t) |
Initialise the generator with four values of type long int . More... | |
double(* | randomWH )(struct generator *self) |
Generate a (pseudo-)random number drawn from the U(0,1) distribution. More... | |
long int *(* | read )(struct generator *self) |
Read the current state of the pseudo-random number generator. More... | |
enum BOOLEAN(* | bernoulli )(struct generator *self, double prob) |
Generate a binomially distributed random variate. More... | |
long int(* | geometric )(struct generator *self, double prob) |
Generate a geometrically distributed random variate. More... | |
long int(* | binomial )(struct generator *self, long int trials, double prob) |
Generate a binomially distributed random variate. More... | |
long int(* | fairdie )(struct generator *self, long int lower_inclusive, long int upper_inclusive) |
Generate a discrete-valued uniformly distributed random variate drawn from a specified range. More... | |
Typedef
of struct
to store and process the four generator seeds.
In ordinary usage, you will not use this typedef directly. Instead, you will use the instance of it called Congruence
which is pre-initialised in randomWH.c. An exception would be if your code requires multiple instances of the random number generator. A second instance can be generated using the following code (failure to initialise this correctly will almost always cause fatal errors at run time).
This generator can be accessed using generator2.init()
, generator2.read()
, etc.
If multiple generators are instantiated, the number sequences generated may overlap; this is certain to occur if two or more are seeded with the same values.
Definition at line 147 of file randomWH.h.
Generate a binomially distributed random variate.
Usage
self | A pointer to the calling struct (required since C does not support the this keyword). |
prob | The probability of success |
Definition at line 324 of file randomWH.h.
long int(* binomial)(struct generator *self, long int trials, double prob) |
Generate a binomially distributed random variate.
Usage
self | A pointer to the calling struct (required since C does not support the this keyword). |
trials | The number of trials |
prob | The probability of success in each trial |
Definition at line 395 of file randomWH.h.
long int(* fairdie)(struct generator *self, long int lower_inclusive, long int upper_inclusive) |
Generate a discrete-valued uniformly distributed random variate drawn from a specified range.
Usage
self | A pointer to the calling struct (required since C does not support the this keyword). |
lower_inclusive | the lowest value of variate that can be returned |
upper_inclusive | the highest value of variate that can be returned |
Definition at line 432 of file randomWH.h.
long int(* geometric)(struct generator *self, double prob) |
Generate a geometrically distributed random variate.
Usage
self | A pointer to the calling struct (required since C does not support the this keyword). |
prob | The probability of success in each trial |
Definition at line 360 of file randomWH.h.
Initialise the generator with four values of type long
int
.
We need to populate the congruent
structure with seed values before calling randomWH()
. This function isolates the initialisation from the implementation.
Usage
x | The seed for the first generator |
y | The seed for the second generator |
z | The seed for the third generator |
t | The seed for the fourth generator |
self | A pointer to the calling struct (required since C does not support the this keyword). |
Definition at line 198 of file randomWH.h.
enum BOOLEAN initialised |
initialised to false; set to true when function pointers updated
Definition at line 155 of file randomWH.h.
double(* randomWH)(struct generator *self) |
Generate a (pseudo-)random number drawn from the U(0,1) distribution.
Usage
double
value drawn (to a good approximation) from a uniform distribution in the range [0,1]Definition at line 248 of file randomWH.h.
long int*(* read)(struct generator *self) |
Read the current state of the pseudo-random number generator.
Usage
long int
values . Definition at line 289 of file randomWH.h.
long int t |
The seed for the fourth generator
Definition at line 154 of file randomWH.h.
long int x |
The seed for the first generator
Definition at line 151 of file randomWH.h.
long int y |
The seed for the second generator
Definition at line 152 of file randomWH.h.
long int z |
The seed for the third generator
Definition at line 153 of file randomWH.h.