Non-uniform random variate generation orpseudo-random number sampling is thenumerical practice of generatingpseudo-random numbers (PRN) that follow a givenprobability distribution.Methods are typically based on the availability of auniformly distributedPRN generator. Computational algorithms are then used to manipulate a singlerandom variate,X, or often several such variates, into a new random variateY such that these values have the required distribution.The first methods were developed forMonte-Carlo simulations in theManhattan Project,[citation needed] published byJohn von Neumann in the early 1950s.[1]
For adiscrete probability distribution with a finite numbern of indices at which theprobability mass functionf takes non-zero values, the basic sampling algorithm is straightforward. The interval [0, 1) is divided inn intervals [0, f(1)), [f(1), f(1) + f(2)), ... The width of intervali equals the probability f(i).One draws a uniformly distributed pseudo-random numberX, and searches for the indexi of the corresponding interval. The so determinedi will have the distribution f(i).
Formalizing this idea becomes easier by using the cumulative distribution function
It is convenient to setF(0) = 0. Then intervals are then simply [F(0), F(1)), [F(1), F(2)), ..., [F(n − 1), F(n)). The main computational task is then to determinei for whichF(i − 1) ≤ X < F(i).
This can be done by different algorithms:
Generic methods for generatingindependent samples:
Generic methods for generatingcorrelated samples (often necessary for unusually-shaped or high-dimensional distributions):
For generating anormal distribution:
For generating aPoisson distribution:
| Library | Beta | Binomial | Cauchy | Chi-squared | Dirichlet | Exponential | F | Gamma | Geometric | Gumbel | Hypergeometric | Laplace | Logistic | Log-normal | Logarithmic | Multinomial | Multivariate hypergeometric | Multivariate normal | Negative binomial | Noncentral chi-squared | Noncentral F | Normal | Pareto | Poisson | Power | Rayleigh | Students's t | Triangular | von Mises | Wald | Zeta |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| NumPy | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| GNU Scientific Library[5] | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes | No | No | Yes | Yes | Yes | ? | Yes | Yes | No | No | No | No |
Any one who considers arithmetical methods of producing random digits is of course, in a state of sin.Also online is alow-quality scan of the original publication.