<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html><head><title>Python: module random</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head><body bgcolor="#f0f0f8"> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading"> <tr bgcolor="#7799ee"> <td valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"> <br><big><big><strong>random</strong></big></big></font></td ><td align=right valign=bottom ><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/lib/python3.10/random.py">/usr/local/lib/python3.10/random.py</a><br><a href="https://docs.python.org/3.10/library/random.html">Module Reference</a></font></td></tr></table> <p><tt><a href="#Random">Random</a> variable generators.<br> <br> bytes<br> -----<br> uniform bytes (values between 0 and 255)<br> <br> integers<br> --------<br> uniform within range<br> <br> sequences<br> ---------<br> pick random element<br> pick random sample<br> pick weighted random sample<br> generate random permutation<br> <br> distributions on the real line:<br> ------------------------------<br> uniform<br> triangular<br> normal (Gaussian)<br> lognormal<br> negative exponential<br> gamma<br> beta<br> pareto<br> Weibull<br> <br> distributions on the circle (angles 0 to 2pi)<br> ---------------------------------------------<br> circular uniform<br> von Mises<br> <br> General notes on the underlying Mersenne Twister core generator:<br> <br> * The period is 2**19937-1.<br> * It is one of the most extensively tested generators in existence.<br> * The <a href="#-random">random</a>() method is implemented in C, executes in a single Python step,<br> and is, therefore, threadsafe.</tt></p> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#aa55cc"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr> <tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td> <td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="os.html">os</a><br> </td><td width="25%" valign=top><a href="_random.html">_random</a><br> </td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ee77aa"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr> <tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td> <td width="100%"><dl> <dt><font face="helvetica, arial"><a href="_random.html#Random">_random.Random</a>(<a href="builtins.html#object">builtins.object</a>) </font></dt><dd> <dl> <dt><font face="helvetica, arial"><a href="random.html#Random">Random</a> </font></dt><dd> <dl> <dt><font face="helvetica, arial"><a href="random.html#SystemRandom">SystemRandom</a> </font></dt></dl> </dd> </dl> </dd> </dl> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="Random">class <strong>Random</strong></a>(<a href="_random.html#Random">_random.Random</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt><a href="#Random">Random</a>(x=None)<br> <br> <a href="#Random">Random</a> number generator base class used by bound module functions.<br> <br> Used to instantiate instances of <a href="#Random">Random</a> to get generators that don't<br> share state.<br> <br> Class <a href="#Random">Random</a> can also be subclassed if you want to use a different basic<br> generator of your own devising: in that case, override the following<br> methods: <a href="#Random-random">random</a>(), <a href="#Random-seed">seed</a>(), <a href="#Random-getstate">getstate</a>(), and <a href="#Random-setstate">setstate</a>().<br> Optionally, implement a <a href="#Random-getrandbits">getrandbits</a>() method so that <a href="#Random-randrange">randrange</a>()<br> can cover arbitrarily large ranges.<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="random.html#Random">Random</a></dd> <dd><a href="_random.html#Random">_random.Random</a></dd> <dd><a href="builtins.html#object">builtins.object</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="Random-__getstate__"><strong>__getstate__</strong></a>(self)</dt><dd><tt># Issue 17489: Since __reduce__ was defined to fix #759889 this is no<br> # longer called; we leave it here because it has been here since random was<br> # rewritten back in 2001 and why risk breaking something.</tt></dd></dl> <dl><dt><a name="Random-__init__"><strong>__init__</strong></a>(self, x=None)</dt><dd><tt>Initialize an instance.<br> <br> Optional argument x controls seeding, as for <a href="#Random">Random</a>.<a href="#Random-seed">seed</a>().</tt></dd></dl> <dl><dt><a name="Random-__reduce__"><strong>__reduce__</strong></a>(self)</dt><dd><tt>Helper for pickle.</tt></dd></dl> <dl><dt><a name="Random-__setstate__"><strong>__setstate__</strong></a>(self, state)</dt></dl> <dl><dt><a name="Random-betavariate"><strong>betavariate</strong></a>(self, alpha, beta)</dt><dd><tt>Beta distribution.<br> <br> Conditions on the parameters are alpha > 0 and beta > 0.<br> Returned values range between 0 and 1.</tt></dd></dl> <dl><dt><a name="Random-choice"><strong>choice</strong></a>(self, seq)</dt><dd><tt>Choose a random element from a non-empty sequence.</tt></dd></dl> <dl><dt><a name="Random-choices"><strong>choices</strong></a>(self, population, weights=None, *, cum_weights=None, k=1)</dt><dd><tt>Return a k sized list of population elements chosen with replacement.<br> <br> If the relative weights or cumulative weights are not specified,<br> the selections are made with equal probability.</tt></dd></dl> <dl><dt><a name="Random-expovariate"><strong>expovariate</strong></a>(self, lambd)</dt><dd><tt>Exponential distribution.<br> <br> lambd is 1.0 divided by the desired mean. It should be<br> nonzero. (The parameter would be called "lambda", but that is<br> a reserved word in Python.) Returned values range from 0 to<br> positive infinity if lambd is positive, and from negative<br> infinity to 0 if lambd is negative.</tt></dd></dl> <dl><dt><a name="Random-gammavariate"><strong>gammavariate</strong></a>(self, alpha, beta)</dt><dd><tt>Gamma distribution. Not the gamma function!<br> <br> Conditions on the parameters are alpha > 0 and beta > 0.<br> <br> The probability distribution function is:<br> <br> x ** (alpha - 1) * math.exp(-x / beta)<br> pdf(x) = --------------------------------------<br> math.gamma(alpha) * beta ** alpha</tt></dd></dl> <dl><dt><a name="Random-gauss"><strong>gauss</strong></a>(self, mu, sigma)</dt><dd><tt>Gaussian distribution.<br> <br> mu is the mean, and sigma is the standard deviation. This is<br> slightly faster than the <a href="#Random-normalvariate">normalvariate</a>() function.<br> <br> Not thread-safe without a lock around calls.</tt></dd></dl> <dl><dt><a name="Random-getstate"><strong>getstate</strong></a>(self)</dt><dd><tt>Return internal state; can be passed to <a href="#Random-setstate">setstate</a>() later.</tt></dd></dl> <dl><dt><a name="Random-lognormvariate"><strong>lognormvariate</strong></a>(self, mu, sigma)</dt><dd><tt>Log normal distribution.<br> <br> If you take the natural logarithm of this distribution, you'll get a<br> normal distribution with mean mu and standard deviation sigma.<br> mu can have any value, and sigma must be greater than zero.</tt></dd></dl> <dl><dt><a name="Random-normalvariate"><strong>normalvariate</strong></a>(self, mu, sigma)</dt><dd><tt>Normal distribution.<br> <br> mu is the mean, and sigma is the standard deviation.</tt></dd></dl> <dl><dt><a name="Random-paretovariate"><strong>paretovariate</strong></a>(self, alpha)</dt><dd><tt>Pareto distribution. alpha is the shape parameter.</tt></dd></dl> <dl><dt><a name="Random-randbytes"><strong>randbytes</strong></a>(self, n)</dt><dd><tt>Generate n random bytes.</tt></dd></dl> <dl><dt><a name="Random-randint"><strong>randint</strong></a>(self, a, b)</dt><dd><tt>Return random integer in range [a, b], including both end points.</tt></dd></dl> <dl><dt><a name="Random-randrange"><strong>randrange</strong></a>(self, start, stop=None, step=1)</dt><dd><tt>Choose a random item from range(start, stop[, step]).<br> <br> This fixes the problem with <a href="#Random-randint">randint</a>() which includes the<br> endpoint; in Python this is usually not what you want.</tt></dd></dl> <dl><dt><a name="Random-sample"><strong>sample</strong></a>(self, population, k, *, counts=None)</dt><dd><tt>Chooses k unique random elements from a population sequence or set.<br> <br> Returns a new list containing elements from the population while<br> leaving the original population unchanged. The resulting list is<br> in selection order so that all sub-slices will also be valid random<br> samples. This allows raffle winners (the sample) to be partitioned<br> into grand prize and second place winners (the subslices).<br> <br> Members of the population need not be hashable or unique. If the<br> population contains repeats, then each occurrence is a possible<br> selection in the sample.<br> <br> Repeated elements can be specified one at a time or with the optional<br> counts parameter. For example:<br> <br> <a href="#Random-sample">sample</a>(['red', 'blue'], counts=[4, 2], k=5)<br> <br> is equivalent to:<br> <br> <a href="#Random-sample">sample</a>(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)<br> <br> To choose a sample from a range of integers, use range() for the<br> population argument. This is especially fast and space efficient<br> for sampling from a large population:<br> <br> <a href="#Random-sample">sample</a>(range(10000000), 60)</tt></dd></dl> <dl><dt><a name="Random-seed"><strong>seed</strong></a>(self, a=None, version=2)</dt><dd><tt>Initialize internal state from a seed.<br> <br> The only supported seed types are None, int, float,<br> str, bytes, and bytearray.<br> <br> None or no argument seeds from current time or from an operating<br> system specific randomness source if available.<br> <br> If *a* is an int, all bits are used.<br> <br> For version 2 (the default), all of the bits are used if *a* is a str,<br> bytes, or bytearray. For version 1 (provided for reproducing random<br> sequences from older versions of Python), the algorithm for str and<br> bytes generates a narrower range of seeds.</tt></dd></dl> <dl><dt><a name="Random-setstate"><strong>setstate</strong></a>(self, state)</dt><dd><tt>Restore internal state from object returned by <a href="#Random-getstate">getstate</a>().</tt></dd></dl> <dl><dt><a name="Random-shuffle"><strong>shuffle</strong></a>(self, x, random=None)</dt><dd><tt>Shuffle list x in place, and return None.<br> <br> Optional argument random is a 0-argument function returning a<br> random float in [0.0, 1.0); if it is the default None, the<br> standard random.random will be used.</tt></dd></dl> <dl><dt><a name="Random-triangular"><strong>triangular</strong></a>(self, low=0.0, high=1.0, mode=None)</dt><dd><tt>Triangular distribution.<br> <br> Continuous distribution bounded by given lower and upper limits,<br> and having a given mode value in-between.<br> <br> <a href="http://en.wikipedia.org/wiki/Triangular_distribution">http://en.wikipedia.org/wiki/Triangular_distribution</a></tt></dd></dl> <dl><dt><a name="Random-uniform"><strong>uniform</strong></a>(self, a, b)</dt><dd><tt>Get a random number in the range [a, b) or [a, b] depending on rounding.</tt></dd></dl> <dl><dt><a name="Random-vonmisesvariate"><strong>vonmisesvariate</strong></a>(self, mu, kappa)</dt><dd><tt>Circular data distribution.<br> <br> mu is the mean angle, expressed in radians between 0 and 2*pi, and<br> kappa is the concentration parameter, which must be greater than or<br> equal to zero. If kappa is equal to zero, this distribution reduces<br> to a uniform random angle over the range 0 to 2*pi.</tt></dd></dl> <dl><dt><a name="Random-weibullvariate"><strong>weibullvariate</strong></a>(self, alpha, beta)</dt><dd><tt>Weibull distribution.<br> <br> alpha is the scale parameter and beta is the shape parameter.</tt></dd></dl> <hr> Class methods defined here:<br> <dl><dt><a name="Random-__init_subclass__"><strong>__init_subclass__</strong></a>(**kwargs)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt><dd><tt>Control how subclasses generate random integers.<br> <br> The algorithm a subclass can use depends on the <a href="#Random-random">random</a>() and/or<br> <a href="#Random-getrandbits">getrandbits</a>() implementation available to it and determines<br> whether it can generate random integers from arbitrarily large<br> ranges.</tt></dd></dl> <hr> Data descriptors defined here:<br> <dl><dt><strong>__dict__</strong></dt> <dd><tt>dictionary for instance variables (if defined)</tt></dd> </dl> <dl><dt><strong>__weakref__</strong></dt> <dd><tt>list of weak references to the object (if defined)</tt></dd> </dl> <hr> Data and other attributes defined here:<br> <dl><dt><strong>VERSION</strong> = 3</dl> <hr> Methods inherited from <a href="_random.html#Random">_random.Random</a>:<br> <dl><dt><a name="Random-getrandbits"><strong>getrandbits</strong></a>(self, k, /)</dt><dd><tt><a href="#Random-getrandbits">getrandbits</a>(k) -> x. Generates an int with k random bits.</tt></dd></dl> <dl><dt><a name="Random-random"><strong>random</strong></a>(self, /)</dt><dd><tt><a href="#Random-random">random</a>() -> x in the interval [0, 1).</tt></dd></dl> <hr> Static methods inherited from <a href="_random.html#Random">_random.Random</a>:<br> <dl><dt><a name="Random-__new__"><strong>__new__</strong></a>(*args, **kwargs)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt><dd><tt>Create and return a new object. See help(type) for accurate signature.</tt></dd></dl> </td></tr></table> <p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#ffc8d8"> <td colspan=3 valign=bottom> <br> <font color="#000000" face="helvetica, arial"><a name="SystemRandom">class <strong>SystemRandom</strong></a>(<a href="random.html#Random">Random</a>)</font></td></tr> <tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td> <td colspan=2><tt><a href="#SystemRandom">SystemRandom</a>(x=None)<br> <br> Alternate random number generator using sources provided<br> by the operating system (such as /dev/urandom on Unix or<br> CryptGenRandom on Windows).<br> <br> Not available on all systems (see os.urandom() for details).<br> </tt></td></tr> <tr><td> </td> <td width="100%"><dl><dt>Method resolution order:</dt> <dd><a href="random.html#SystemRandom">SystemRandom</a></dd> <dd><a href="random.html#Random">Random</a></dd> <dd><a href="_random.html#Random">_random.Random</a></dd> <dd><a href="builtins.html#object">builtins.object</a></dd> </dl> <hr> Methods defined here:<br> <dl><dt><a name="SystemRandom-getrandbits"><strong>getrandbits</strong></a>(self, k)</dt><dd><tt><a href="#SystemRandom-getrandbits">getrandbits</a>(k) -> x. Generates an int with k random bits.</tt></dd></dl> <dl><dt><a name="SystemRandom-getstate"><strong>getstate</strong></a> = <a href="#SystemRandom-_notimplemented">_notimplemented</a>(self, *args, **kwds)</dt></dl> <dl><dt><a name="SystemRandom-randbytes"><strong>randbytes</strong></a>(self, n)</dt><dd><tt>Generate n random bytes.</tt></dd></dl> <dl><dt><a name="SystemRandom-random"><strong>random</strong></a>(self)</dt><dd><tt>Get the next random number in the range [0.0, 1.0).</tt></dd></dl> <dl><dt><a name="SystemRandom-seed"><strong>seed</strong></a>(self, *args, **kwds)</dt><dd><tt>Stub method. Not used for a system random number generator.</tt></dd></dl> <dl><dt><a name="SystemRandom-setstate"><strong>setstate</strong></a> = <a href="#SystemRandom-_notimplemented">_notimplemented</a>(self, *args, **kwds)</dt></dl> <hr> Methods inherited from <a href="random.html#Random">Random</a>:<br> <dl><dt><a name="SystemRandom-__getstate__"><strong>__getstate__</strong></a>(self)</dt><dd><tt># Issue 17489: Since __reduce__ was defined to fix #759889 this is no<br> # longer called; we leave it here because it has been here since random was<br> # rewritten back in 2001 and why risk breaking something.</tt></dd></dl> <dl><dt><a name="SystemRandom-__init__"><strong>__init__</strong></a>(self, x=None)</dt><dd><tt>Initialize an instance.<br> <br> Optional argument x controls seeding, as for <a href="#Random">Random</a>.<a href="#SystemRandom-seed">seed</a>().</tt></dd></dl> <dl><dt><a name="SystemRandom-__reduce__"><strong>__reduce__</strong></a>(self)</dt><dd><tt>Helper for pickle.</tt></dd></dl> <dl><dt><a name="SystemRandom-__setstate__"><strong>__setstate__</strong></a>(self, state)</dt></dl> <dl><dt><a name="SystemRandom-betavariate"><strong>betavariate</strong></a>(self, alpha, beta)</dt><dd><tt>Beta distribution.<br> <br> Conditions on the parameters are alpha > 0 and beta > 0.<br> Returned values range between 0 and 1.</tt></dd></dl> <dl><dt><a name="SystemRandom-choice"><strong>choice</strong></a>(self, seq)</dt><dd><tt>Choose a random element from a non-empty sequence.</tt></dd></dl> <dl><dt><a name="SystemRandom-choices"><strong>choices</strong></a>(self, population, weights=None, *, cum_weights=None, k=1)</dt><dd><tt>Return a k sized list of population elements chosen with replacement.<br> <br> If the relative weights or cumulative weights are not specified,<br> the selections are made with equal probability.</tt></dd></dl> <dl><dt><a name="SystemRandom-expovariate"><strong>expovariate</strong></a>(self, lambd)</dt><dd><tt>Exponential distribution.<br> <br> lambd is 1.0 divided by the desired mean. It should be<br> nonzero. (The parameter would be called "lambda", but that is<br> a reserved word in Python.) Returned values range from 0 to<br> positive infinity if lambd is positive, and from negative<br> infinity to 0 if lambd is negative.</tt></dd></dl> <dl><dt><a name="SystemRandom-gammavariate"><strong>gammavariate</strong></a>(self, alpha, beta)</dt><dd><tt>Gamma distribution. Not the gamma function!<br> <br> Conditions on the parameters are alpha > 0 and beta > 0.<br> <br> The probability distribution function is:<br> <br> x ** (alpha - 1) * math.exp(-x / beta)<br> pdf(x) = --------------------------------------<br> math.gamma(alpha) * beta ** alpha</tt></dd></dl> <dl><dt><a name="SystemRandom-gauss"><strong>gauss</strong></a>(self, mu, sigma)</dt><dd><tt>Gaussian distribution.<br> <br> mu is the mean, and sigma is the standard deviation. This is<br> slightly faster than the <a href="#SystemRandom-normalvariate">normalvariate</a>() function.<br> <br> Not thread-safe without a lock around calls.</tt></dd></dl> <dl><dt><a name="SystemRandom-lognormvariate"><strong>lognormvariate</strong></a>(self, mu, sigma)</dt><dd><tt>Log normal distribution.<br> <br> If you take the natural logarithm of this distribution, you'll get a<br> normal distribution with mean mu and standard deviation sigma.<br> mu can have any value, and sigma must be greater than zero.</tt></dd></dl> <dl><dt><a name="SystemRandom-normalvariate"><strong>normalvariate</strong></a>(self, mu, sigma)</dt><dd><tt>Normal distribution.<br> <br> mu is the mean, and sigma is the standard deviation.</tt></dd></dl> <dl><dt><a name="SystemRandom-paretovariate"><strong>paretovariate</strong></a>(self, alpha)</dt><dd><tt>Pareto distribution. alpha is the shape parameter.</tt></dd></dl> <dl><dt><a name="SystemRandom-randint"><strong>randint</strong></a>(self, a, b)</dt><dd><tt>Return random integer in range [a, b], including both end points.</tt></dd></dl> <dl><dt><a name="SystemRandom-randrange"><strong>randrange</strong></a>(self, start, stop=None, step=1)</dt><dd><tt>Choose a random item from range(start, stop[, step]).<br> <br> This fixes the problem with <a href="#SystemRandom-randint">randint</a>() which includes the<br> endpoint; in Python this is usually not what you want.</tt></dd></dl> <dl><dt><a name="SystemRandom-sample"><strong>sample</strong></a>(self, population, k, *, counts=None)</dt><dd><tt>Chooses k unique random elements from a population sequence or set.<br> <br> Returns a new list containing elements from the population while<br> leaving the original population unchanged. The resulting list is<br> in selection order so that all sub-slices will also be valid random<br> samples. This allows raffle winners (the sample) to be partitioned<br> into grand prize and second place winners (the subslices).<br> <br> Members of the population need not be hashable or unique. If the<br> population contains repeats, then each occurrence is a possible<br> selection in the sample.<br> <br> Repeated elements can be specified one at a time or with the optional<br> counts parameter. For example:<br> <br> <a href="#SystemRandom-sample">sample</a>(['red', 'blue'], counts=[4, 2], k=5)<br> <br> is equivalent to:<br> <br> <a href="#SystemRandom-sample">sample</a>(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)<br> <br> To choose a sample from a range of integers, use range() for the<br> population argument. This is especially fast and space efficient<br> for sampling from a large population:<br> <br> <a href="#SystemRandom-sample">sample</a>(range(10000000), 60)</tt></dd></dl> <dl><dt><a name="SystemRandom-shuffle"><strong>shuffle</strong></a>(self, x, random=None)</dt><dd><tt>Shuffle list x in place, and return None.<br> <br> Optional argument random is a 0-argument function returning a<br> random float in [0.0, 1.0); if it is the default None, the<br> standard random.random will be used.</tt></dd></dl> <dl><dt><a name="SystemRandom-triangular"><strong>triangular</strong></a>(self, low=0.0, high=1.0, mode=None)</dt><dd><tt>Triangular distribution.<br> <br> Continuous distribution bounded by given lower and upper limits,<br> and having a given mode value in-between.<br> <br> <a href="http://en.wikipedia.org/wiki/Triangular_distribution">http://en.wikipedia.org/wiki/Triangular_distribution</a></tt></dd></dl> <dl><dt><a name="SystemRandom-uniform"><strong>uniform</strong></a>(self, a, b)</dt><dd><tt>Get a random number in the range [a, b) or [a, b] depending on rounding.</tt></dd></dl> <dl><dt><a name="SystemRandom-vonmisesvariate"><strong>vonmisesvariate</strong></a>(self, mu, kappa)</dt><dd><tt>Circular data distribution.<br> <br> mu is the mean angle, expressed in radians between 0 and 2*pi, and<br> kappa is the concentration parameter, which must be greater than or<br> equal to zero. If kappa is equal to zero, this distribution reduces<br> to a uniform random angle over the range 0 to 2*pi.</tt></dd></dl> <dl><dt><a name="SystemRandom-weibullvariate"><strong>weibullvariate</strong></a>(self, alpha, beta)</dt><dd><tt>Weibull distribution.<br> <br> alpha is the scale parameter and beta is the shape parameter.</tt></dd></dl> <hr> Class methods inherited from <a href="random.html#Random">Random</a>:<br> <dl><dt><a name="SystemRandom-__init_subclass__"><strong>__init_subclass__</strong></a>(**kwargs)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt><dd><tt>Control how subclasses generate random integers.<br> <br> The algorithm a subclass can use depends on the <a href="#SystemRandom-random">random</a>() and/or<br> <a href="#SystemRandom-getrandbits">getrandbits</a>() implementation available to it and determines<br> whether it can generate random integers from arbitrarily large<br> ranges.</tt></dd></dl> <hr> Data descriptors inherited from <a href="random.html#Random">Random</a>:<br> <dl><dt><strong>__dict__</strong></dt> <dd><tt>dictionary for instance variables (if defined)</tt></dd> </dl> <dl><dt><strong>__weakref__</strong></dt> <dd><tt>list of weak references to the object (if defined)</tt></dd> </dl> <hr> Data and other attributes inherited from <a href="random.html#Random">Random</a>:<br> <dl><dt><strong>VERSION</strong> = 3</dl> <hr> Static methods inherited from <a href="_random.html#Random">_random.Random</a>:<br> <dl><dt><a name="SystemRandom-__new__"><strong>__new__</strong></a>(*args, **kwargs)<font color="#909090"><font face="helvetica, arial"> from <a href="builtins.html#type">builtins.type</a></font></font></dt><dd><tt>Create and return a new object. See help(type) for accurate signature.</tt></dd></dl> </td></tr></table></td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#eeaa77"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr> <tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td> <td width="100%"><dl><dt><a name="-betavariate"><strong>betavariate</strong></a>(alpha, beta)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Beta distribution.<br> <br> Conditions on the parameters are alpha > 0 and beta > 0.<br> Returned values range between 0 and 1.</tt></dd></dl> <dl><dt><a name="-choice"><strong>choice</strong></a>(seq)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Choose a random element from a non-empty sequence.</tt></dd></dl> <dl><dt><a name="-choices"><strong>choices</strong></a>(population, weights=None, *, cum_weights=None, k=1)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Return a k sized list of population elements chosen with replacement.<br> <br> If the relative weights or cumulative weights are not specified,<br> the selections are made with equal probability.</tt></dd></dl> <dl><dt><a name="-expovariate"><strong>expovariate</strong></a>(lambd)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Exponential distribution.<br> <br> lambd is 1.0 divided by the desired mean. It should be<br> nonzero. (The parameter would be called "lambda", but that is<br> a reserved word in Python.) Returned values range from 0 to<br> positive infinity if lambd is positive, and from negative<br> infinity to 0 if lambd is negative.</tt></dd></dl> <dl><dt><a name="-gammavariate"><strong>gammavariate</strong></a>(alpha, beta)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Gamma distribution. Not the gamma function!<br> <br> Conditions on the parameters are alpha > 0 and beta > 0.<br> <br> The probability distribution function is:<br> <br> x ** (alpha - 1) * math.exp(-x / beta)<br> pdf(x) = --------------------------------------<br> math.gamma(alpha) * beta ** alpha</tt></dd></dl> <dl><dt><a name="-gauss"><strong>gauss</strong></a>(mu, sigma)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Gaussian distribution.<br> <br> mu is the mean, and sigma is the standard deviation. This is<br> slightly faster than the <a href="#-normalvariate">normalvariate</a>() function.<br> <br> Not thread-safe without a lock around calls.</tt></dd></dl> <dl><dt><a name="-getrandbits"><strong>getrandbits</strong></a>(k, /)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt><a href="#-getrandbits">getrandbits</a>(k) -> x. Generates an int with k random bits.</tt></dd></dl> <dl><dt><a name="-getstate"><strong>getstate</strong></a>()<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Return internal state; can be passed to <a href="#-setstate">setstate</a>() later.</tt></dd></dl> <dl><dt><a name="-lognormvariate"><strong>lognormvariate</strong></a>(mu, sigma)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Log normal distribution.<br> <br> If you take the natural logarithm of this distribution, you'll get a<br> normal distribution with mean mu and standard deviation sigma.<br> mu can have any value, and sigma must be greater than zero.</tt></dd></dl> <dl><dt><a name="-normalvariate"><strong>normalvariate</strong></a>(mu, sigma)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Normal distribution.<br> <br> mu is the mean, and sigma is the standard deviation.</tt></dd></dl> <dl><dt><a name="-paretovariate"><strong>paretovariate</strong></a>(alpha)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Pareto distribution. alpha is the shape parameter.</tt></dd></dl> <dl><dt><a name="-randbytes"><strong>randbytes</strong></a>(n)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Generate n random bytes.</tt></dd></dl> <dl><dt><a name="-randint"><strong>randint</strong></a>(a, b)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Return random integer in range [a, b], including both end points.</tt></dd></dl> <dl><dt><a name="-random"><strong>random</strong></a>()<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt><a href="#-random">random</a>() -> x in the interval [0, 1).</tt></dd></dl> <dl><dt><a name="-randrange"><strong>randrange</strong></a>(start, stop=None, step=1)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Choose a random item from range(start, stop[, step]).<br> <br> This fixes the problem with <a href="#-randint">randint</a>() which includes the<br> endpoint; in Python this is usually not what you want.</tt></dd></dl> <dl><dt><a name="-sample"><strong>sample</strong></a>(population, k, *, counts=None)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Chooses k unique random elements from a population sequence or set.<br> <br> Returns a new list containing elements from the population while<br> leaving the original population unchanged. The resulting list is<br> in selection order so that all sub-slices will also be valid random<br> samples. This allows raffle winners (the sample) to be partitioned<br> into grand prize and second place winners (the subslices).<br> <br> Members of the population need not be hashable or unique. If the<br> population contains repeats, then each occurrence is a possible<br> selection in the sample.<br> <br> Repeated elements can be specified one at a time or with the optional<br> counts parameter. For example:<br> <br> <a href="#-sample">sample</a>(['red', 'blue'], counts=[4, 2], k=5)<br> <br> is equivalent to:<br> <br> <a href="#-sample">sample</a>(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)<br> <br> To choose a sample from a range of integers, use range() for the<br> population argument. This is especially fast and space efficient<br> for sampling from a large population:<br> <br> <a href="#-sample">sample</a>(range(10000000), 60)</tt></dd></dl> <dl><dt><a name="-seed"><strong>seed</strong></a>(a=None, version=2)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Initialize internal state from a seed.<br> <br> The only supported seed types are None, int, float,<br> str, bytes, and bytearray.<br> <br> None or no argument seeds from current time or from an operating<br> system specific randomness source if available.<br> <br> If *a* is an int, all bits are used.<br> <br> For version 2 (the default), all of the bits are used if *a* is a str,<br> bytes, or bytearray. For version 1 (provided for reproducing random<br> sequences from older versions of Python), the algorithm for str and<br> bytes generates a narrower range of seeds.</tt></dd></dl> <dl><dt><a name="-setstate"><strong>setstate</strong></a>(state)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Restore internal state from object returned by <a href="#-getstate">getstate</a>().</tt></dd></dl> <dl><dt><a name="-shuffle"><strong>shuffle</strong></a>(x, random=None)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Shuffle list x in place, and return None.<br> <br> Optional argument random is a 0-argument function returning a<br> random float in [0.0, 1.0); if it is the default None, the<br> standard random.random will be used.</tt></dd></dl> <dl><dt><a name="-triangular"><strong>triangular</strong></a>(low=0.0, high=1.0, mode=None)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Triangular distribution.<br> <br> Continuous distribution bounded by given lower and upper limits,<br> and having a given mode value in-between.<br> <br> <a href="http://en.wikipedia.org/wiki/Triangular_distribution">http://en.wikipedia.org/wiki/Triangular_distribution</a></tt></dd></dl> <dl><dt><a name="-uniform"><strong>uniform</strong></a>(a, b)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Get a random number in the range [a, b) or [a, b] depending on rounding.</tt></dd></dl> <dl><dt><a name="-vonmisesvariate"><strong>vonmisesvariate</strong></a>(mu, kappa)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Circular data distribution.<br> <br> mu is the mean angle, expressed in radians between 0 and 2*pi, and<br> kappa is the concentration parameter, which must be greater than or<br> equal to zero. If kappa is equal to zero, this distribution reduces<br> to a uniform random angle over the range 0 to 2*pi.</tt></dd></dl> <dl><dt><a name="-weibullvariate"><strong>weibullvariate</strong></a>(alpha, beta)<font color="#909090"><font face="helvetica, arial"> method of <a href="random.html#Random">Random</a> instance</font></font></dt><dd><tt>Weibull distribution.<br> <br> alpha is the scale parameter and beta is the shape parameter.</tt></dd></dl> </td></tr></table><p> <table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section"> <tr bgcolor="#55aa55"> <td colspan=3 valign=bottom> <br> <font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr> <tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td> <td width="100%"><strong>__all__</strong> = ['Random', 'SystemRandom', 'betavariate', 'choice', 'choices', 'expovariate', 'gammavariate', 'gauss', 'getrandbits', 'getstate', 'lognormvariate', 'normalvariate', 'paretovariate', 'randbytes', 'randint', 'random', 'randrange', 'sample', 'seed', 'setstate', ...]</td></tr></table> </body></html>