Spaces:
Running
on
Zero
Running
on
Zero
File size: 49,364 Bytes
b2add11 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
<!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> |