Initialize the generator when the module is first imported. If x is omitted or None,Ĭurrent system time is used current system time is also used to Optional argument xĬan be any hashable object. Initialize the basic random number generator. See the referencesīelow for a recent variant that repairs these flaws.Ĭhanged in version 2.3: Substituted MersenneTwister for Wichmann-Hill. Known to fail some stringent randomness tests. Too short by contemporary standards, and the sequence generated is
Wichmann-Hill generator can no longer be recommended: its period is Wichmann-Hill algorithm as the core generator. Reproduce results from earlier versions of Python, which used the The class provides a backward compatible way to
WichmannHill class that implements an alternative generator in New in version 2.4: the getrandbits() method.Īs an example of subclassing, the random module provides the Selections over an arbitrarily large range. Getrandbits() method - this allows randrange() to produce Random(), seed(), getstate(), setstate() and Sequences seen by each thread don’t overlap.Ĭlass Random can also be subclassed if you want to use a differentīasic generator of your own devising: in that case, override the The jumpahead() method to make it likely that the generated This is especially useful for multi-threaded programs,Ĭreating a different instance of Random for each thread, and using Your own instances of Random to get generators that don’t share Hidden instance of the random.Random class. The functions supplied by this module are actually bound methods of a Is not suitable for all purposes, and is completely unsuitable for However, being completely deterministic, it Mersenne Twister is one of the most extensively tested random number Underlying implementation in C is both fast and threadsafe. Produces 53-bit precision floats and has a period of 2**19937-1. Python uses the Mersenne Twister as the core generator. Which generates a random float uniformly in the semi-open range [0.0,ġ.0). For generating distributions of angles, the von MisesĪlmost all module functions depend on the basic function random(), (Gaussian), lognormal, negative exponential, gamma, and betaĭistributions. On the real line, there are functions to compute uniform, normal Permutation of a list in-place, and a function for random sampling Selection of a random element, a function to generate a random This module implements pseudo-random number generators for variousįor integers, uniform selection from a range. random - Generate pseudo-random numbers ¶