There are no implemented interfaces.
VERSION
(type:
int
)
1
getrandbits(...)
getrandbits(k) -> x. Generates a long int with k random bits.
betavariate(alpha, beta)
Beta distribution.
Conditions on the parameters are alpha > -1 and beta} > -1. Returned values range between 0 and 1.
choice(seq)
Choose a random element from a non-empty sequence.
expovariate(lambd)
Exponential distribution.
lambd is 1.0 divided by the desired mean. (The parameter would be called "lambda", but that is a reserved word in Python.) Returned values range from 0 to positive infinity.
gammavariate(alpha, beta)
Gamma distribution. Not the gamma function!
Conditions on the parameters are alpha > 0 and beta > 0.
gauss(mu, sigma)
Gaussian distribution.
mu is the mean, and sigma is the standard deviation. This is slightly faster than the normalvariate() function.
Not thread-safe without a lock around calls.
getstate()
Return internal state; can be passed to setstate() later.
jumpahead(n)
Act as if n calls to random() were made, but quickly.
n is an int, greater than or equal to 0.
Example use: If you have 2 threads and know that each will consume no more than a million random numbers, create two Random objects r1 and r2, then do r2.setstate(r1.getstate()) r2.jumpahead(1000000) Then r1 and r2 will use guaranteed-disjoint segments of the full period.
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.
normalvariate(mu, sigma)
Normal distribution.
mu is the mean, and sigma is the standard deviation.
paretovariate(alpha)
Pareto distribution. alpha is the shape parameter.
randint(a, b)
Return random integer in range [a, b], including both end points.
random()
Get the next random number in the range [0.0, 1.0).
randrange(start, stop=None, step=1, int=<type 'int'>, default=None, maxwidth=9007199254740992L)
Choose a random item from range(start, stop[, step]).
This fixes the problem with randint() which includes the
endpoint; in Python this is usually not what you want.
Do not supply the int
, default
, and maxwidth
arguments.
sample(population, k)
Chooses k unique random elements from a population sequence.
Returns a new list containing elements from the population while leaving the original population unchanged. The resulting list is in selection order so that all sub-slices will also be valid random samples. This allows raffle winners (the sample) to be partitioned into grand prize and second place winners (the subslices).
Members of the population need not be hashable or unique. If the population contains repeats, then each occurrence is a possible selection in the sample.
To choose a sample in a range of integers, use xrange as an argument. This is especially fast and space efficient for sampling from a large population: sample(xrange(10000000), 60)
seed(a=None)
Initialize internal state from hashable object.
None or no argument seeds from current time or from an operating system specific randomness source if available.
If a is not None or an int or long, hash(a) is used instead.
If a is an int or long, a is used directly. Distinct values between 0 and 27814431486575L inclusive are guaranteed to yield distinct internal states (this guarantee is specific to the default Wichmann-Hill generator).
setstate(state)
Restore internal state from object returned by getstate().
shuffle(x, random=None, int=<type 'int'>)
x, random=random.random -> shuffle list x in place; return None.
Optional arg random is a 0-argument function returning a random float in [0.0, 1.0); by default, the standard random.random.
Note that for even rather small len(x), the total number of permutations of x is larger than the period of most random number generators; this implies that "most" permutations of a long sequence can never be generated.
uniform(a, b)
Get a random number in the range [a, b).
vonmisesvariate(mu, kappa)
Circular data distribution.
mu is the mean angle, expressed in radians between 0 and 2pi, 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 2pi.
weibullvariate(alpha, beta)
Weibull distribution.
alpha is the scale parameter and beta is the shape parameter.
whseed(a=None)
Seed from hashable object's hash code.
None or no argument seeds from current time. It is not guaranteed that objects with distinct hash codes lead to distinct internal states.
This is obsolete, provided for compatibility with the seed routine used prior to Python 2.1. Use the .seed() method instead.
There are no known subclasses.