3
\2k ã @ sØ d Z ddlmZ ddlmZmZ ddl m
ZmZ
mZmZmZ ddl mZmZmZmZ ddlmZ ddlm Z!m"Z# ddl$m%Z& dd l'Z(dd l)Z*d
ddd
ddddddddddddddddddd d!gZ+d"e
d2ƒ ed$ƒ Z,d$e Z-ed%ƒZ.d&ed'ƒ Z/d(Z0d)e0 Z1dd l2Z2G d*d
„ d
e2j3ƒZ3G d+d!„ d!e3ƒZ4d,d-„ Z5d3d/d0„Z6e3ƒ Z7e7j8Z8e7j9Z9e7j:Z:e7j;Z;e7jZ>e7j?Z?e7j@Z@e7jAZAe7jBZBe7jCZCe7jDZDe7jEZEe7jFZFe7jGZGe7jHZHe7jIZIe7jJZJe7jKZKe7jLZLe7jMZMeNd1k�rÔe6ƒ d S )4a° Random variable generators.
integers
--------
uniform within range
sequences
---------
pick random element
pick random sample
pick weighted random sample
generate random permutation
distributions on the real line:
------------------------------
uniform
triangular
normal (Gaussian)
lognormal
negative exponential
gamma
beta
pareto
Weibull
distributions on the circle (angles 0 to 2pi)
---------------------------------------------
circular uniform
von Mises
General notes on the underlying Mersenne Twister core generator:
* The period is 2**19937-1.
* It is one of the most extensively tested generators in existence.
* The random() method is implemented in C, executes in a single Python step,
and is, therefore, threadsafe.
é )Úwarn)Ú
MethodTypeÚBuiltinMethodType)ÚlogÚexpÚpiÚeÚceil)ÚsqrtÚacosÚcosÚsin)Úurandom)ÚSetÚSequence)Úsha512NÚRandomÚseedÚrandomÚuniformÚrandintÚchoiceÚsampleÚ randrangeÚshuffleÚ
normalvariateÚlognormvariateÚexpovariateÚvonmisesvariateÚgammavariateÚ
triangularÚgaussÚbetavariateÚ
paretovariateÚweibullvariateÚgetstateÚsetstateÚgetrandbitsÚchoicesÚSystemRandomé g à?g @g @g ð?g @é5 é c s e Zd ZdZdZd;dd„Zd<‡ fdd„ Z‡ fd d
„Z‡ fdd„Zd
d„ Z dd„ Z
dd„ Zddefdd„Z
dd„ Zede> eeefdd„Zdd„ Zd=dd„Zdd„ Zd>ddd œd!d"„Zd#d$„ Zd?d'd(„Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Z d7d8„ Z!d9d:„ Z"‡ Z#S )@r aã Random number generator base class used by bound module functions.
Used to instantiate instances of Random to get generators that don't
share state.
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(), and setstate().
Optionally, implement a getrandbits() method so that randrange()
can cover arbitrarily large ranges.
é Nc C s | j |ƒ d| _dS )zeInitialize an instance.
Optional argument x controls seeding, as for Random.seed().
N)r Ú
gauss_next)ÚselfÚx© r1 ú/usr/lib64/python3.6/random.pyÚ__init__W s
zRandom.__init__r, c sâ |dkr†t |ttfƒr†t |tƒr*|jdƒn|}|rBt|d ƒd> nd}x"tt|ƒD ]}d| |A d@ }qRW |t|ƒN }|d
kr‚dn|}|dkrÌt |tttfƒrÌt |tƒr°|jƒ }|t |ƒj
ƒ 7 }tj|dƒ}t
ƒ j|ƒ d | _d S )a 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 an int, all bits are used.
For version 2 (the default), all of the bits are used if *a* is a str,
bytes, or bytearray. For version 1 (provided for reproducing random
sequences from older versions of Python), the algorithm for str and
bytes generates a narrower range of seeds.
é zlatin-1r é iCB l ÿÿÿÿ r, ÚbigNéÿÿÿÿéþÿÿÿ)Ú
isinstanceÚstrÚbytesÚdecodeÚordÚmapÚlenÚ bytearrayÚencodeÚ_sha512ZdigestÚintÚ
from_bytesÚsuperr r. )r/ ÚaÚversionr0 Úc)Ú __class__r1 r2 r ` s
zRandom.seedc s | j tƒ jƒ | jfS )z9Return internal state; can be passed to setstate() later.)ÚVERSIONrE r% r. )r/ )rI r1 r2 r% € s zRandom.getstatec s¢ |d }|dkr*|\}}| _ tƒ j|ƒ nt|dkrŒ|\}}| _ ytdd„ |D ƒƒ}W n( tk
r| } zt|‚W Y dd}~X nX tƒ j|ƒ ntd|| jf ƒ‚dS )z:Restore internal state from object returned by getstate().r r- r, c s s | ]}|d V qdS )r, é Nl r1 )Ú.0r0 r1 r1 r2 ú ‘ s z"Random.setstate..Nz?state with version %s passed to Random.setstate() of version %s)r. rE r&