Skip to main content

Random

The random module provides random number generation and random distributions.

Factories

NameDescription
random_distributionConstructs a probability distribution of the given name with the given parameters.

Types

NameDescription
BernoulliReturns true or false with the probability of true given by the parameter p (with default value 0.5).
BinomialReturns an integer corresponding to the number of successes in t (with default value 1) trials given that the probability of success is p (with default value 0.5).
CauchyThe ratio of two normal distributions with location parameter a (with default value 0.0) and half-width half-maximum b (with default value 1.0).
ChiSquaredModels the distribution of the sum of squares of n (with default value 1.0) independent standard normal variables.
DiscreteProduces random integers with probabilities determined by the given weights (with default value [1.0]).
DistributionParent distribution for all other distributions. Guarantees that all distributions have a method sample, parameters and parameter
ExponentialReturns the time until the next random event if the rate of events is lambda (with default value 1.0).
ExtremeValueGumbel Type-I distribution modelling the maximum of a finite sample with location a (with default value 0.0) and scale b (with default value 1.0).
FisherFThe ratio of two chi-squared distributions with degrees of freedom m (with default value 1.0) and n (with default value 1.0).
GammaRepresents the Gamma distribution with shape parameter alpha (with default value 1.0) and scale parameter beta (with default value 1.0).
GeometricReturns the average number of failures before success when the chance of success is p (with default value 0.5).
LognormalModels a random variable with a normally distributed logarithm with log-mean m (with default value 0.0) and log-deviation s (with default value 1.0).
NegativeBinomialReturns an integer corresponding to the number of failures before exactly k (with default value 1) successes given that the probability of success is p (with default value 0.5).
NormalNormal (Gaussian) distribution parameterized by mean (with default value 0.0) and stddev (with default value 1.0).
PiecewiseConstantReturns random real numbers uniformly distributed within the given intervals (with default value [0.0, 1.0]), and densities (with default value [1.0]).
PiecewiseLinearReturns random real numbers distributed linearly within the given intervals with default value [0.0,1.0], and densities with default value [1.0].
PoissonReturns the number of occurences over a fixed interval given the mean (with default value 1.0) number of occurences.
RandomDeviceGenerates a random number from a machine device.
RandomGeneratorGenerates a random number according to the Mersenne Twister algorithm. Can be constructed with the random_generator factory.
StudentTModels the distribution of sample variances for n (with default value 1.0) independent standard normal variables.
UniformIntegerUniformly samples integer random values on the interval between a (with default value 0) and b (with default value max_integer()) (inclusive).
UniformRealUniformly samples real random values on the interval between a (with default value 0.0) and b (with default value 1.0) inclusive of bounds.
WeibullWeibull distribution with shape parameters a (with default value 1.0) and scale parameter b (with default value 1.0).

Module Functions

NameDescription
randomGenerates a random integer on the interval [0, 9223372036854775807]
random_deviceProduces a random device used to generate low performance random numbers.
random_generatorProduces a random number generator seeded with the default random device
stringReturns a standardized string representation for a Normal.