Real-Valued Distributions: Random
Real-Valued Distributions: Random
Real-Valued Distributions: Random
random.random()
Return the next random floating point number in the range [0.0, 1.0).
random.uniform(a, b)
random.triangular(low, high, mode)
random.betavariate(alpha, beta)
random.expovariate(lambd)
random.gammavariate(alpha, beta)
random.lognormvariate(mu, sigma)
Log normal distribution. If you take the natural logarithm of this distribution, you’ll
get a normal distribution with mean mu and standard deviation sigma. mu can
have any value, and sigma must be greater than zero.
random.normalvariate(mu, sigma)
random.vonmisesvariate(mu, kappa)
mu is the mean angle, expressed in radians between 0 and 2*pi, and kappa is
the concentration parameter, which must be greater than or equal to zero.
If kappa is equal to zero, this distribution reduces to a uniform random angle over
the range 0 to 2*pi.
random.paretovariate(alpha)
random.weibullvariate(alpha,
beta)
Alternative Generator
class random.Random([seed])
class random.SystemRando
m([seed])
Class that uses the os.urandom() function for generating random numbers
from sources provided by the operating system. Not available on all systems.
Does not rely on software state, and sequences are not reproducible.
Accordingly, the seed() method has no effect and is ignored.
The getstate() and setstate() methods raise NotImplementedError if
called.
Notes on
Reproducibility
Sometimes it is useful to be
able to reproduce the
sequences given by a
pseudo-random number
generator. By re-using a
seed value, the same
sequence should be
reproducible from run to run
as long as multiple threads
are not running.
If a new seeding
method is added,
then a backward
compatible seeder
will be offered.
The
generator’s random(
) method will
continue to produce
the same sequence
when the compatible
seeder is given the
same seed.
Examples
Basic examples:
>>>
>>> random()
# Random float: 0.0
<= x < 1.0
0.37444887175646646
>>> expovariate(1 / 5)
# Interval between
arrivals averaging 5
seconds
5.148957571865031
>>> randrange(10)
# Integer from 0 to 9
inclusive
7
Simulations: