Random number generation in Python

The Python module random contains functions for generating random numbers according to several common distributions.

DistributionPython function(s)
Uniformrandom(), uniform(a, b)
Betabetavariate(alpha, beta)
Exponentialexpovariate(lambda)
Gammagammavariate(alpha, beta)
Normalgauss(mean, sigma), normalvariate(mean, sigma)
Lognormallognormalvariate(mu, sigma)
Paretoparetovariate(alpha)

There are, however, a few common distributions not on the list above. Code is available here for the following distributions.

SciPy has a large collection of random number generation functions as methods on distribution objects. See Distributions in SciPy.

See also:

For daily tips on Python and scientific computing, follow @SciPyTip on Twitter.

Scipytip twitter icon