Next / Previous / Contents / TCC Help System / NM Tech homepage

20.7. The random module: random number generation

randrange([start,]stop[,step])

Return a random element from the sequence range(start,stop,step) .

randint(x,y)

Returns a random integer in the closed interval [x,y]; that is, any result r will satisfy x <= r <= y.

choice(L)

Returns a randomly selected element from a sequence L.

shuffle(L)

Randomly permute the elements of a sequence L.

random()

Returns a random float in the half-open interval [0.0, 1.0); that is, for any result r, 0.0 <= r < 1.0.

uniform(x,y)

Returns a random float in the half-open interval [x,y).

normalrand(m,s)

Generate a normally distributed pseudorandom number with mean m and standard deviation s.

An assortment of other pseudorandom distributions is available: Beta, circular uniform, exponential, gamma, Gaussian, log normal, Von Mises, Pareto, and Weibull distributions. See the Python Library Reference for details.