easyRNG
1.2
BSD licensed random number generators for C and Fortran
|
The random number distributions API. More...
Typedefs | |
typedef struct _easy_ran_discrete_t | easy_ran_discrete_t |
Functions | |
double | easy_ran_gaussian (const easy_rng *r, double sigma) |
double | easy_ran_gaussian_ziggurat (const easy_rng *r, double sigma) |
double | easy_ran_gaussian_ratio_method (const easy_rng *r, double sigma) |
double | easy_ran_ugaussian (const easy_rng *r) |
double | easy_ran_ugaussian_ratio_method (const easy_rng *r) |
double | easy_ran_exponential (const easy_rng *r, double mu) |
double | easy_ran_cauchy (const easy_rng *r, double a) |
double | easy_ran_gamma (const easy_rng *r, double k, double theta) |
double | easy_ran_flat (const easy_rng *r, double a, double b) |
double | easy_ran_lognormal (const easy_rng *r, double mu, double sigma) |
double | easy_ran_chisq (const easy_rng *r, double k) |
double | easy_ran_fdist (const easy_rng *r, double d_1, double d_2) |
double | easy_ran_tdist (const easy_rng *r, double nu) |
double | easy_ran_weibull (const easy_rng *r, double lambda, double k) |
easy_ran_discrete_t * | easy_ran_discrete_preproc (size_t K, const double *P) |
size_t | easy_ran_discrete (const easy_rng *r, const easy_ran_discrete_t *g) |
void | easy_ran_discrete_free (easy_ran_discrete_t *g) |
unsigned int | easy_ran_poisson (const easy_rng *r, double lambda) |
unsigned int | easy_ran_bernoulli (const easy_rng *r, double p) |
unsigned int | easy_ran_binomial (const easy_rng *r, double p, unsigned int n) |
unsigned int | easy_ran_negative_binomial (const easy_rng *r, double p, unsigned int n) |
unsigned int | easy_ran_geometric (const easy_rng *r, double p) |
The random number distributions API.
This header provides wrappers around the random number distributions that are offered by C++11's random
templates. GSL's random number distributions, upon which this API is based, offers considerably more types of distributions. In case one of these (rather exotic) distributions is needed, the user is recommended to use GSL instead of this library.
typedef struct _easy_ran_discrete_t easy_ran_discrete_t |
An intentionally opaque structure containing a lookup table of a discrete distribution
Instances will only be available through pointers, and should be obtained and freed after usage through easy_ran_discrete_preproc() and easy_ran_discrete_free(), respectively.
double easy_ran_gaussian | ( | const easy_rng * | r, |
double | sigma | ||
) |
Generate double precision real numbers according to a normal distribution
The probability density function of the normal distribution is defined as:
\[ f(x; \sigma) = \frac{1}{\sigma\sqrt{2\pi}}\exp\left(-\frac{1}{2}\left(\frac{x}{\sigma}\right)^2\right) \]
with \(\sigma\) the standard deviation.
r | The random number generator instance |
sigma | The standard deviation of the normal distribution |
double easy_ran_gaussian_ziggurat | ( | const easy_rng * | r, |
double | sigma | ||
) |
Generate double precision real numbers according to a normal distribution
r | The random number generator instance |
sigma | The standard deviation of the normal distribution |
double easy_ran_gaussian_ratio_method | ( | const easy_rng * | r, |
double | sigma | ||
) |
Generate double precision real numbers according to a normal distribution
r | The random number generator instance |
sigma | The standard deviation of the normal distribution |
double easy_ran_ugaussian | ( | const easy_rng * | r | ) |
Generate double precision real numbers according to a unit normal distribution
The probability density function of the unit (or standard) normal distribution is defined as:
\[ f(x) = \frac{1}{\sqrt{2\pi}}\exp\left(-\frac{x^2}{2}\right) \]
r | The random number generator instance |
double easy_ran_ugaussian_ratio_method | ( | const easy_rng * | r | ) |
Generate double precision real numbers according to a unit normal distribution
r | The random number generator instance |
double easy_ran_exponential | ( | const easy_rng * | r, |
double | mu | ||
) |
Generate double precision random numbers according to an exponential distribution
The probability density function of the exponential distribution is defined as:
\[ f(x;\mu) = \frac{1}{\mu}\exp\left(-\frac{x}{\mu}\right) \]
with \(\mu\) the inverse rate (also the distribution mean or scale factor) for positive \(x\)
r | The random number generator instance |
mu | The inverse rate |
double easy_ran_cauchy | ( | const easy_rng * | r, |
double | a | ||
) |
Generate double precision random numbers according to a Cauchy distribution
The probability density function of the Cauchy (or Lorentz, as it is widely known in spectroscopy) distribution is defined as:
\[ f(x;a) = \frac{1}{\pi a\left[1 + \left(\frac{x}{a}\right)^2\right]} \]
with \(a\) the scale parameter
r | The random number generator instance |
a | The scale parameter |
double easy_ran_gamma | ( | const easy_rng * | r, |
double | k, | ||
double | theta | ||
) |
Generate double precision random numbers according to a Gamma distribution
The probability density function of the Gamma distribution is defined as:
\[ f(x;k,\theta) = \frac{1}{\Gamma(k) \theta^k} x^{k-1} \exp\left(-\frac{x}{\theta}\right) \]
with \(k\) the shape parameter and \(\theta\) for positive \(x\)
r | The random number generator instance |
k | The shape parameter (must be strictly positive) |
theta | The scale parameter (must be strictly positive) |
double easy_ran_flat | ( | const easy_rng * | r, |
double | a, | ||
double | b | ||
) |
Generate double precision random numbers according to a flat distribution
The probability density function of the flat (uniform) distribution is defined as:
\[ f(x;a,b) = \frac{1}{b - a} \]
with \(a\) and \(b\) the minimum and maximum values of the interval respectively.
r | The random number generator instance |
a | The minimum value of the sampling interval |
b | The maximum value of the sampling interval |
double easy_ran_lognormal | ( | const easy_rng * | r, |
double | mu, | ||
double | sigma | ||
) |
Generate double precision random numbers according to a log-normal distribution
The probability density function of the log-normal distribution is defined as:
\[ f(x;\mu,\sigma) = \frac{1}{x \sigma \sqrt{2 \pi}} \exp\left(-\frac{(\ln(x) - \mu)^2}{2 \sigma^2}\right) \]
with \(\mu\) the location parameter and \(\sigma\) the scale factor, for positive \(x\)
r | The random number generator instance |
mu | The position parameter |
sigma | The scale parameter (must be strictly positive) |
double easy_ran_chisq | ( | const easy_rng * | r, |
double | k | ||
) |
Generate double precision random numbers according to a chi-squared distribution
The probability density function of the chi-squared distribution is defined as:
\[ f(x;k) = \frac{1}{2^{\frac{k}{2}}\Gamma\left(\frac{k}{2}\right)}x^{\frac{k}{2}-1}\exp\left(-\frac{x}{2}\right) \]
with \(k\) the degrees of freedom, for positive \(x\)
r | The random number generator instance |
k | The degrees of freedom |
double easy_ran_fdist | ( | const easy_rng * | r, |
double | d_1, | ||
double | d_2 | ||
) |
Generate double precision random numbers according to an F distribution
The probability density function of the F-distribution is defined as:
\[ f(x;d_1,d_2) = \frac{\sqrt{\frac{(d_1x)^{d_1}d_2^{d_2}}{(d_1x+d_2)^{(d_1+d_2)}}}}{xB\left(\frac{d_1}{2},\frac{d_2}{2}\right)} \]
with \(d_1\) and \(d_2\) the degrees of freedom and B the Beta function, for positive \(x\)
r | The random number generator instance |
d_1 | The first degrees of freedom |
d_2 | The second degrees of freedom |
double easy_ran_tdist | ( | const easy_rng * | r, |
double | nu | ||
) |
Generate double precision random numbers according to a [Student's t-distribution](https://en.wikipedia.org/wiki/Student's_t-distribution)
The probability density function of the Student's t-distribution is defined as:
\[ f(x;\nu) = \frac{\Gamma\left(\frac{\nu+1}{2}\right)}{\sqrt{\nu\pi}\Gamma\left(\frac{\nu}{2}\right)}\left(1+\frac{x^2}{\nu}\right)^{-\frac{\nu+1}{2}} \]
with \(\nu\) the degrees of freedom.
r | The random number generator instance |
nu | The degrees of freedom |
double easy_ran_weibull | ( | const easy_rng * | r, |
double | lambda, | ||
double | k | ||
) |
Generate double precision random numbers according to a Weibull distribution
The probability density function of the Weibull distribution is defined as:
\[ f(x;\lambda,k) = \frac{k}{\lambda}\left(\frac{x}{\lambda}\right)^{k-1}\exp\left(-\left(\frac{x}{\lambda}\right)^k\right) \]
with \(\lambda\) the scale parameter and \(k\) the shape parameter, for positive \(x\)
r | The random number generator instance |
lambda | The scale parameter |
k | The shape parameter |
easy_ran_discrete_t* easy_ran_discrete_preproc | ( | size_t | K, |
const double * | P | ||
) |
Generate a lookup table for a discrete distribution
Free this table after usage with easy_ran_discrete_free()
K | The length of the array P |
P | An array of length K , containing the (positive) weights of the events |
P
K
argument as the size of the P array can be determined from the variable itself. size_t easy_ran_discrete | ( | const easy_rng * | r, |
const easy_ran_discrete_t * | g | ||
) |
Generate positive integers according to a discrete distribution
r | The random number generator instance |
g | The lookup table |
void easy_ran_discrete_free | ( | easy_ran_discrete_t * | g | ) |
Frees the memory associated with a discrete distribution lookup table
g | The lookup table |
unsigned int easy_ran_poisson | ( | const easy_rng * | r, |
double | lambda | ||
) |
Generate positive integers according to a Poisson distribution
The probability function of the Poisson distribution is defined as:
\[ f(k;\lambda) = \frac{\lambda^k\exp(-\lambda)}{k!} \]
with \(\lambda\) the average number of events in an interval, for positive integers \(k\)
r | The random number generator instance |
lambda | The average number of events in an interval |
unsigned int easy_ran_bernoulli | ( | const easy_rng * | r, |
double | p | ||
) |
Generate zeroes and ones according to a Bernoulli distribution
The probability function of the Bernoulli distribution is defined as:
\[ f(k;p) = p^k(1-p)^{1-k} \]
with \(p\) the success probability between 0 and 1, for integers \(k\) restricted to 0 and 1
r | The random number generator instance |
p | The success probability |
unsigned int easy_ran_binomial | ( | const easy_rng * | r, |
double | p, | ||
unsigned int | n | ||
) |
Generate positive integers according to a binomial distribution
The probability function of the binomial distribution is defined as:
\[ f(k;p,n) = {{n}\choose{k}}p^k(1-p)^{n-k} \]
with \(p\) the success probability between 0 and 1 for each trial, and \(n\) the number of trials, for positive integers \(k\)
r | The random number generator instance |
p | The success probability for each trial |
n | The number of trials |
unsigned int easy_ran_negative_binomial | ( | const easy_rng * | r, |
double | p, | ||
unsigned int | n | ||
) |
Generate positive integers according to a negative binomial distribution
The probability function of the negative binomial distribution is defined as:
\[ f(k;p,n) = {{n+k-1}\choose{k}}p^n(1-p)^k \]
with \(p\) the success probability between 0 and 1 for each trial, and \(n\) the number of successful trials, for positive integers \(k\), the number of failures
r | The random number generator instance |
p | The success probability for each trial |
n | The number of successful trials |
unsigned int easy_ran_geometric | ( | const easy_rng * | r, |
double | p | ||
) |
Generate positive integers according to a geometric distribution
The probability function of the geometric distribution is defined as:
\[ f(k;p) = (1-p)^{k-1}p \]
with \(p\) the success probability between 0 and 1 for each trial, for positive integers \(k\) greater than one.
r | The random number generator instance |
p | The success probability for each trial |