random.Random¶
-
class
random.Random(x=None)[source]¶ Random number generator base class used by bound module functions.
Used to instantiate instances of Random to get generators that don’t share state. Especially useful for multi-threaded programs, creating a different instance of Random for each thread, and using the jumpahead() method to ensure that the generated sequences seen by each thread don’t overlap.
Class Random can also be subclassed if you want to use a different basic generator of your own devising: in that case, override the following methods: random(), seed(), getstate(), setstate() and jumpahead(). Optionally, implement a getrandbits() method so that randrange() can cover arbitrarily large ranges.
Methods¶
__format__ |
default object formatter |
__getstate__() |
|
__init__([x]) |
Initialize an instance. |
__new__((S, ...) |
|
__reduce__() |
|
__reduce_ex__ |
helper for pickle |
__setstate__(state) |
|
__sizeof__(() -> int) |
size of object in memory, in bytes |
__subclasshook__ |
Abstract classes can override this to customize issubclass(). |
_randbelow(n[, _log, _int, _maxwidth, ...]) |
Return a random int in the range [0,n) |
betavariate(alpha, beta) |
Beta distribution. |
choice(seq) |
Choose a random element from a non-empty sequence. |
expovariate(lambd) |
Exponential distribution. |
gammavariate(alpha, beta) |
Gamma distribution. |
gauss(mu, sigma) |
Gaussian distribution. |
getrandbits(...) |
|
getstate() |
Return internal state; can be passed to setstate() later. |
jumpahead(n) |
Change the internal state to one that is likely far away from the current state. |
lognormvariate(mu, sigma) |
Log normal distribution. |
normalvariate(mu, sigma) |
Normal distribution. |
paretovariate(alpha) |
Pareto distribution. |
randint(a, b) |
Return random integer in range [a, b], including both end points. |
random(() -> x in the interval [0, 1).) |
|
randrange(start[, stop, step, _int, _maxwidth]) |
Choose a random item from range(start, stop[, step]). |
sample(population, k) |
Chooses k unique random elements from a population sequence. |
seed([a]) |
Initialize internal state from hashable object. |
setstate(state) |
Restore internal state from object returned by getstate(). |
shuffle(x[, random]) |
x, random=random.random -> shuffle list x in place; return None. |
triangular([low, high, mode]) |
Triangular distribution. |
uniform(a, b) |
Get a random number in the range [a, b) or [a, b] depending on rounding. |
vonmisesvariate(mu, kappa) |
Circular data distribution. |
weibullvariate(alpha, beta) |
Weibull distribution. |