PartMC  2.2.0
Defines | Functions/Subroutines | 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.

Defines

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

Functions/Subroutines

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

Variables

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

Detailed Description

Wrapper routines for GSL random number functions.

Definition in file rand_gsl.c.


Define Documentation

#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.

#define PMC_RAND_GSL_INIT_FAIL   1

Result code indicating initialization failure.

Definition at line 26 of file rand_gsl.c.

#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.

#define PMC_RAND_GSL_SUCCESS   0

Result code indicating successful completion.

Definition at line 23 of file rand_gsl.c.


Function/Subroutine Documentation

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.

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.

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.

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.

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.

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.

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

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.