randomWH API
Generation of Pseudo-Random Variates
|
A pseudorandom number generator with good statistical properties. More...
#include "randomWH.h"
Go to the source code of this file.
Functions | |
void | Congruence_init (Congruence *self, long int x, long int y, long int z, long int t) |
Initialise the generator with four values of type long int . More... | |
void | randomWH_error (const char *message) |
A very basic error handling function. More... | |
long int * | Congruence_read (Congruence *self) |
Read the current state of the pseudo-random number generator. More... | |
double | randomWH_null (Congruence *self) |
Generate an error message and triggers a program exit if the calling struct has not been initialised properly. More... | |
double | randomWH_32 (Congruence *self) |
Generate a (pseudo-)random number drawn from the U(0,1) distribution using the 32-bit W-H algorithm . More... | |
double | randomWH_64 (Congruence *self) |
Generate a (pseudo-)random number drawn from the U(0,1) distribution using the 64-bit W-H algorithm . More... | |
long int | randomWH_geometric (Congruence *self, double prob) |
Generate a geometrically distributed random variate. More... | |
enum BOOLEAN | randomWH_bernoulli (Congruence *self, double prob) |
Generate a Bernoulli random variate. More... | |
long int | randomWH_binomial (Congruence *self, long int trials, double prob) |
Generate a binomially distributed random variate. More... | |
long int | randomWH_fairdie (Congruence *self, long int lower_inclusive, long int upper_inclusive) |
Generate a discrete-valued uniformly distributed random variate drawn from a specified range. More... | |
Variables | |
Congruence | congruent |
A pseudorandom number generator with good statistical properties.
Details
This implements the algorithm described by Wichmann and Hill in
Two implementations are provided. One is for compilers that use 32 bits to store variables of the long int
type. A faster algorithm is also provided for use with compilers that feature a 64-bit long int
type. The algorithm to be used is determined automatically at run time.
Definition in file randomWH.c.
void Congruence_init | ( | Congruence * | self, |
long int | x, | ||
long int | y, | ||
long int | z, | ||
long int | t | ||
) |
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 52 of file randomWH.c.
long int* Congruence_read | ( | Congruence * | self) |
Read the current state of the pseudo-random number generator.
Usage
self | A pointer to the calling struct (required since C does not support the this keyword). |
long int
values . Definition at line 125 of file randomWH.c.
double randomWH_32 | ( | Congruence * | self) |
Generate a (pseudo-)random number drawn from the U(0,1) distribution using the 32-bit W-H algorithm .
self | A pointer to the calling struct (required since C does not support the this keyword). |
double
value drawn (to a good approximation) from a uniform distribution in the range [0,1] Definition at line 161 of file randomWH.c.
double randomWH_64 | ( | Congruence * | self) |
Generate a (pseudo-)random number drawn from the U(0,1) distribution using the 64-bit W-H algorithm .
self | A pointer to the calling struct (required since C does not support the this keyword). |
double
value drawn (to a good approximation) from a uniform distribution in the range [0,1] Definition at line 198 of file randomWH.c.
enum BOOLEAN randomWH_bernoulli | ( | Congruence * | self, |
double | prob | ||
) |
Generate a Bernoulli 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 268 of file randomWH.c.
long int randomWH_binomial | ( | Congruence * | 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). |
prob | The probability of success in each trial |
trials | The number of trials |
Definition at line 288 of file randomWH.c.
void randomWH_error | ( | const char * | message) |
A very basic error handling function.
This just prints an error message to stderr
and then exits.
Usage
message | A byte string containing a message about the error. |
Definition at line 90 of file randomWH.c.
long int randomWH_fairdie | ( | Congruence * | 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 307 of file randomWH.c.
long int randomWH_geometric | ( | Congruence * | 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 223 of file randomWH.c.
double randomWH_null | ( | Congruence * | self) |
Generate an error message and triggers a program exit if the calling struct has not been initialised properly.
This simulates exception handling for the exception "you forgot to read the documentation".
self | A pointer to the calling struct (required since C does not support the this keyword). |
Definition at line 141 of file randomWH.c.
The initialised congruent struct -
Definition at line 12 of file randomWH.c.