This section describes the rnd module, which contains the functions for generating random variates from a specified distribution. Samples from the distributions described in this section can be obtained using any of the random number generators from the module rng as an underlying source of randomness (see Random Number Generator Algorithms).
In the simplest cases a non-uniform distribution can be obtained analytically from the uniform distribution of a random number generator by applying an appropriate transformation, which requires the inverse cumulative distribution function. This method uses one call to the random number generator. More complicated distributions are created by the “acceptance-rejection” method, which compares the desired distribution against a distribution which is similar and known analytically. This usually requires several samples from the generator.
LGSL also provides cumulative distribution functions and inverse cumulative distribution functions, sometimes referred to as quantile functions; these are in the module randist.
This function returns a Gaussian random variate, with mean zero and standard deviation sigma. The probability distribution for Gaussian random variates is,
for \(x\) in the range \(-\infty\) to \(+\infty\). Use the transformation \(z = \mu + x\) on the numbers returned by gaussian() to obtain a Gaussian distribution with mean \(\mu\). This function uses the Box-Mueller algorithm which requires two calls to the random number generator r.
This function returns a random variate from the exponential distribution with mean mu. The distribution is,
for \(x \ge 0\).
The chi-squared (\(\chi^2\)) distribution arises in statistics. If \(Y_i\) are \(n\) independent gaussian random variates with unit variance then the sum-of-squares,
has a chi-squared distribution with \(n\) degrees of freedom.
This function returns a random variate from the chi-squared distribution with \(\nu\) degrees of freedom. The distribution function is,
for \(x \ge 0\).
This function returns a random variate from the Laplace distribution with width a. The distribution is,
for \(-\infty < x < +\infty\).
The t-distribution arises in statistics. If \(Y_1\) has a normal distribution and \(Y_2\) has a chi-squared distribution with \(\nu\) degrees of freedom then the ratio,
has a t-distribution \(t(x;\nu)\) with \(\nu\) degrees of freedom.
This function returns a random variate from the t-distribution. The distribution function is,
for \(-\infty < x < +\infty\).
This function returns a random variate from the Cauchy distribution with scale parameter a. The probability distribution for Cauchy random variates is,
for \(-\infty < x < +\infty\). The Cauchy distribution is also known as the Lorentz distribution.
This function returns a random variate from the Rayleigh distribution with scale parameter sigma. The distribution is,
for \(x > 0\).
The F-distribution arises in statistics. If \(Y_1\) and \(Y_2\) are chi-squared deviates with \(\nu_1\) and \(\nu_2\) degrees of freedom then the ratio,
has an F-distribution \(F(x; \nu_1, \nu_2)\).
This function returns a random variate from the F-distribution with degrees of freedom \(\nu_1\) and \(\nu_2\). The distribution function is,
for \(x \ge 0\).
This function returns a random variate from the gamma distribution. The distribution function is,
for \(x > 0\).
The gamma distribution with an integer parameter a is known as the Erlang distribution. The variates are computed using the Marsaglia-Tsang fast gamma method.
This function returns a random variate from the beta distribution. The distribution function is,
for \(0 \le x \le 1\).
This function provides random variates from the upper tail of a Gaussian distribution with standard deviation sigma. The values returned are larger than the lower limit a, which must be positive. The method is based on Marsaglia’s famous rectangle-wedge-tail algorithm (Ann. Math. Stat. 32, 894–899 (1961)), with this aspect explained in Knuth, v2, 3rd ed, p139,586 (exercise 11).
The probability distribution for Gaussian tail random variates is,
for \(x > a\) where \(N(a; \sigma)\) is the normalization constant,
This function returns a random variate from the exponential power distribution with scale parameter a and exponent b. The distribution is,
for \(x \ge 0\). For b = 1 this reduces to the Laplace distribution. For b = 2 it has the same form as a gaussian distribution, but with \(a = \sqrt{2} \sigma\).
This function returns a random variate from the lognormal distribution. The distribution function is,
for \(x > 0\).
This function returns a random integer from the binomial distribution, the number of successes in n independent trials with probability p. The probability distribution for binomial variates is,
for \(0 \le k \le n\).
This function returns a random integer from the Poisson distribution with mean mu. The probability distribution for Poisson variates is,
for k >= 0.