Random Module
The random module provides functions for generating random numbers, letters, and selecting elements randomly from a sequence.
random.betavariate (alpha, beta)
Beta distribution. Requires alpha > 0 and beta > 0. Returns a value between 0 and 1.
random.choice (sequence)
Returns a random element from a non-empty sequence.
random.expovariate (lambd)
Exponential distribution. lambd is 1/desired mean and must not be zero. Returns values from 0 to positive infinity if lambd is positive, and from negative infinity to 0 if lambd is negative.
random.gammavariate (alpha, beta)
Gamma distribution. Requires alpha > 0 and beta > 0.
random.gauss (mean, standard_deviation)
Gaussian distribution.
random.getrandbits (N)
Returns N random bits.
random.getstate ()
Returns the internal state of the generator.
random.lognormvariate (mu, sigma)
Log-normal distribution. The natural logarithm of this distribution yields a normal distribution with mean mu and standard deviation sigma. mu can be any value, and sigma must be greater than zero.
random.normalvariate (mu, sigma)
Normal distribution. mu is the mean, and sigma is the standard deviation.
random.paretovariate (alpha)
Pareto distribution.
random.randint (A, B)
Returns a random integer N such that A ≤ N ≤ B.
random.random ()
Returns a random number from 0 to 1.
random.randrange (start, stop, step)
Returns a randomly selected number from a sequence.
random.sample (population, k)
Returns a list of length k from the sequence population.
random.seed (X, version=2)
Initializes the random number generator. If X is not specified, the system time is used.
random.setstate (state)
Restores the internal state of the generator. The state must be obtained using getstate().
random.shuffle (sequence, rand)
Shuffles the sequence (modifies the sequence itself). Does not work for immutable objects.
random.triangular (low, high, mode)
Returns a random floating-point number, low ≤ N ≤ high. Mode is the distribution.
random.uniform (A, B)
Returns a random floating-point number, A ≤ N ≤ B (or B ≤ N ≤ A).
random.vonmisesvariate (mu, kappa)
mu is the mean angle, expressed in radians from 0 to 2π. kappa is the concentration parameter, which must be greater than or equal to zero. If kappa is zero, this distribution reduces to a random angle in the range from 0 to 2π.
random.weibullvariate (alpha, beta)
Weibull distribution.