PartMC  2.6.1
Macros | Functions | Variables
rand_gsl.c File Reference

Wrapper routines for GSL random number functions. More...

Include dependency graph for rand_gsl.c:

Go to the source code of this file.

Macros

#define PMC_RAND_GSL_SUCCESS   0
 Result code indicating successful completion. More...
 
#define PMC_RAND_GSL_INIT_FAIL   1
 Result code indicating initialization failure. More...
 
#define PMC_RAND_GSL_NOT_INIT   2
 Result code indicating the generator was not initialized when it should have been. More...
 
#define PMC_RAND_GSL_ALREADY_INIT   3
 Result code indicating the generator was already initialized when an initialization was attempted. More...
 

Functions

int pmc_srand_gsl (int seed)
 Initialize the random number generator with the given seed. More...
 
int pmc_rand_finalize_gsl ()
 Cleanup and deallocate the random number generator. More...
 
int pmc_rand_gsl (double *harvest)
 Generate a uniform random number in $[0,1)$. More...
 
int pmc_rand_int_gsl (int n, int *harvest)
 Generate a uniform random integer in $[1,n]$. More...
 
int pmc_rand_normal_gsl (double mean, double stddev, double *harvest)
 Generate a normally-distributed random number. More...
 
int pmc_rand_poisson_gsl (double mean, int *harvest)
 Generate a Poisson-distributed random integer. More...
 
int pmc_rand_binomial_gsl (int n, double p, int *harvest)
 Generate a Binomial-distributed random integer. More...
 

Variables

static gsl_rng * pmc_rand_gsl_rng = NULL
 Private internal-use variable to store the random number generator. More...
 

Detailed Description

Wrapper routines for GSL random number functions.

Definition in file rand_gsl.c.

Macro Definition Documentation

◆ PMC_RAND_GSL_ALREADY_INIT

#define PMC_RAND_GSL_ALREADY_INIT   3

Result code indicating the generator was already initialized when an initialization was attempted.

Definition at line 34 of file rand_gsl.c.

◆ PMC_RAND_GSL_INIT_FAIL

#define PMC_RAND_GSL_INIT_FAIL   1

Result code indicating initialization failure.

Definition at line 26 of file rand_gsl.c.

◆ PMC_RAND_GSL_NOT_INIT

#define PMC_RAND_GSL_NOT_INIT   2

Result code indicating the generator was not initialized when it should have been.

Definition at line 30 of file rand_gsl.c.

◆ PMC_RAND_GSL_SUCCESS

#define PMC_RAND_GSL_SUCCESS   0

Result code indicating successful completion.

Definition at line 23 of file rand_gsl.c.

Function Documentation

◆ pmc_rand_binomial_gsl()

int pmc_rand_binomial_gsl ( int  n,
double  p,
int *  harvest 
)

Generate a Binomial-distributed random integer.

Parameters
nThe sample size for the distribution.
pThe sample probability for the distribution.
harvestA pointer to the generated random number.
Returns
PMC_RAND_GSL_SUCCESS on success, otherwise an error code.

Definition at line 142 of file rand_gsl.c.

◆ pmc_rand_finalize_gsl()

int pmc_rand_finalize_gsl ( )

Cleanup and deallocate the random number generator.

This must be called after pmc_srand_gsl().

Returns
PMC_RAND_GSL_SUCCESS on success, otherwise an error code.

Definition at line 65 of file rand_gsl.c.

◆ pmc_rand_gsl()

int pmc_rand_gsl ( double *  harvest)

Generate a uniform random number in $[0,1)$.

Parameters
harvestA pointer to the generated random number.
Returns
PMC_RAND_GSL_SUCCESS on success, otherwise an error code.

Definition at line 80 of file rand_gsl.c.

◆ pmc_rand_int_gsl()

int pmc_rand_int_gsl ( int  n,
int *  harvest 
)

Generate a uniform random integer in $[1,n]$.

Parameters
nThe upper limit of the random integer.
harvestA pointer to the generated random number.
Returns
PMC_RAND_GSL_SUCCESS on success, otherwise an error code.

Definition at line 95 of file rand_gsl.c.

◆ pmc_rand_normal_gsl()

int pmc_rand_normal_gsl ( double  mean,
double  stddev,
double *  harvest 
)

Generate a normally-distributed random number.

Parameters
meanThe mean of the distribution.
stddevThe standard deviation of the distribution.
harvestA pointer to the generated random number.
Returns
PMC_RAND_GSL_SUCCESS on success, otherwise an error code.

Definition at line 111 of file rand_gsl.c.

◆ pmc_rand_poisson_gsl()

int pmc_rand_poisson_gsl ( double  mean,
int *  harvest 
)

Generate a Poisson-distributed random integer.

Parameters
meanThe mean of the distribution.
harvestA pointer to the generated random number.
Returns
PMC_RAND_GSL_SUCCESS on success, otherwise an error code.

Definition at line 126 of file rand_gsl.c.

◆ pmc_srand_gsl()

int pmc_srand_gsl ( int  seed)

Initialize the random number generator with the given seed.

This must be called before any other GSL random number functions are called.

Parameters
seedThe random seed to use.
Returns
PMC_RAND_GSL_SUCCESS on success, otherwise an error code.
See also
pmc_rand_finalize_gsl() to cleanup the generator.

Definition at line 45 of file rand_gsl.c.

Variable Documentation

◆ pmc_rand_gsl_rng

gsl_rng* pmc_rand_gsl_rng = NULL
static

Private internal-use variable to store the random number generator.

Definition at line 19 of file rand_gsl.c.