Spade

Mini Shell

Directory:~$ /proc/self/root/usr/lib64/python3.6/__pycache__/
Upload File

[Home] [System Details] [Kill Me]
Current File:~$ //proc/self/root/usr/lib64/python3.6/__pycache__/random.cpython-36.pyc

3


 \2k�@s�dZddlmZddlmZmZddl	m
ZmZ
mZmZmZddl	mZmZmZmZddlmZddlm
Z!m"Z#ddl$m%Z&dd	l'Z(dd	l)Z*d
ddd
ddddddddddddddddddd
d!gZ+d"e
d2�ed$�Z,d$eZ-ed%�Z.d&ed'�Z/d(Z0d)e0Z1dd	l2Z2Gd*d
�d
e2j3�Z3Gd+d!�d!e3�Z4d,d-�Z5d3d/d0�Z6e3�Z7e7j8Z8e7j9Z9e7j:Z:e7j;Z;e7j<Z<e7j=Z=e7j>Z>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�cseZdZdZdZd;dd�Zd<�fdd�	Z�fd	d
�Z�fdd�Zd
d�Z	dd�Z
dd�Zddefdd�Z
dd�Zede>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)@ra�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.

    �NcCs|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__Ws
zRandom.__init__r,cs�|dkr�t|ttf�r�t|t�r*|jd�n|}|rBt|d�d>nd}x"tt|�D]}d||Ad@}qRW|t|�N}|d
kr�dn|}|dkr�t|tttf�r�t|t�r�|j�}|t	|�j
�7}tj|d�}t
�j|�d	|_d	S)aInitialize 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�iCBl����r,�bigN������)�
isinstance�str�bytes�decode�ord�map�len�	bytearray�encode�_sha512Zdigest�int�
from_bytes�superrr.)r/�a�versionr0�c)�	__class__r1r2r`s
zRandom.seedcs|jt�j�|jfS)z9Return internal state;
can be passed to setstate()
later.)�VERSIONrEr%r.)r/)rIr1r2r%�szRandom.getstatecs�|d}|dkr*|\}}|_t�j|�nt|dkr�|\}}|_ytdd�|D��}Wn(tk
r|}zt|�WYdd}~XnXt�j|�ntd||jf��dS)z:Restore
internal state from object returned by
getstate().rr-r,css|]}|dVqdS)r,�
Nlr1)�.0r0r1r1r2�	<genexpr>�sz"Random.setstate.<locals>.<genexpr>Nz?state
with version %s passed to Random.setstate() of version
%s)r.rEr&�tuple�
ValueError�	TypeErrorrJ)r/�staterGZ
internalstater)rIr1r2r&�szRandom.setstatecCs|j�S)N)r%)r/r1r1r2�__getstate__�szRandom.__getstate__cCs|j|�dS)N)r&)r/rQr1r1r2�__setstate__�szRandom.__setstate__cCs|jf|j�fS)N)rIr%)r/r1r1r2�
__reduce__�szRandom.__reduce__r4c
Cs||�}||krtd��|dkr:|dkr2|j|�Std��||�}||krRtd��||}|dkrx|dkrx||j|�S|dkr�td|||f��||�}||kr�td��|dkr�||d|}	n"|dkr�||d|}	ntd	��|	dkr�td��|||j|	�S)
z�Choose a random item from range(start, stop[, step]).

        This fixes the problem with randint() which includes the
        endpoint; in Python this is usually not what you want.

        z!non-integer arg 1 for randrange()Nrzempty range for
randrange()z non-integer stop for randrange()r4z'empty range for
randrange() (%d,%d, %d)z non-integer step for randrange()zzero step for
randrange())rO�
_randbelow)
r/�start�stop�step�_intZistartZistop�widthZistep�nr1r1r2r�s4

zRandom.randrangecCs|j||d�S)zJReturn
random integer in range [a, b], including both end points.
       
r4)r)r/rF�br1r1r2r�szRandom.randintc
Cs�|j}|j}||�|ks$||�|krN|j�}	||	�}
x|
|krH||	�}
q6W|
S||krltd�||�|�S|dkr|td��||}|||}|�}
x|
|kr�|�}
q�W||
|�|S)zCReturn a random int in the range [0,n).  Raises ValueError
if n==0.z�Underlying random() generator does not supply 
enough bits to choose from a population range this large.
To remove the range limitation, add a getrandbits() method.rzBoundary
cannot be zero)rr'�
bit_length�_warnrO)
r/r[rC�maxsize�typeZMethodZ
BuiltinMethodrr'�k�rZrem�limitr1r1r2rU�s&


zRandom._randbelowcCs:y|jt|��}Wntk
r0td�d�YnX||S)z2Choose a random element from a non-empty
sequence.z$Cannot choose from an empty sequenceN)rUr?rO�
IndexError)r/�seq�ir1r1r2r�s
z
Random.choicecCs�|dkrR|j}x�ttdt|���D]*}||d�}||||||<||<q"WnLt}xFttdt|���D]0}||�|d�}||||||<||<qjWdS)z�Shuffle
list x in place, and return None.

        Optional argument random is a 0-argument function returning a
        random float in [0.0, 1.0); if it is the default None, the
        standard random.random will be used.

       
Nr4)rU�reversed�ranger?rC)r/r0r�	randbelowrf�jrYr1r1r2rs	
zRandom.shufflecCs(t|t�rt|�}t|t�s$td��|j}t|�}d|koD|knsRtd��dg|}d}|dkr�|dtt	|dd��7}||kr�t
|�}x�t|�D]0}|||�}	||	||<|||d	||	<q�WnRt�}
|
j
}xDt|�D]8}||�}	x|	|
k�r
||�}	q�W||	�||	||<q�W|S)
a=Chooses k unique random elements from a population sequence or set.

        Returns a new list containing elements from the population while
        leaving the original population unchanged.  The resulting list is
        in selection order so that all sub-slices will also be valid random
        samples.  This allows raffle winners (the sample) to be partitioned
        into grand prize and second place winners (the subslices).

        Members of the population need not be hashable or unique.  If the
        population contains repeats, then each occurrence is a possible
        selection in the sample.

        To choose a sample in a range of integers, use range as an
argument.
        This is especially fast and space efficient for sampling from a
        large population:   sample(range(10000000), 60)
        z>Population must be a sequence or set.  For dicts, use
list(d).rz,Sample larger than population or is
negativeN��r*r-r4)r9�_SetrN�	_SequencerPrUr?rO�_ceil�_log�listrh�set�add)r/�
populationrarir[�resultZsetsizeZpoolrfrjZselectedZselected_addr1r1r2rs6


z
Random.sample)�cum_weightsracs�|j��dkrN|dkr>t�t�������fdd�t|�D�Sttj|���n|dk	r^td��t��t��krvtd��t	j
��d�t��d�������fdd�t|�D�S)	z�Return
a k sized list of population elements chosen with replacement.

        If the relative weights or cumulative weights are not specified,
        the selections are made with equal probability.

       
Ncsg|]}�������qSr1r1)rLrf)rYrtr�totalr1r2�
<listcomp>csz"Random.choices.<locals>.<listcomp>z2Cannot
specify both weights and cumulative weightsz3The number of weights does not
match the
populationr4cs$g|]}������d���qS)rr1)rLrf)�bisectrv�hirtrrwr1r2rxlsr7)rrCr?rhrq�
_itertools�
accumulaterPrO�_bisectry)r/rtZweightsrvrar1)rYryrvrzrtrrwr2r(Ws
zRandom.choicescCs||||j�S)zHGet
a random number in the range [a, b) or [a, b] depending on
rounding.)r)r/rFr\r1r1r2rsszRandom.uniform���?cCsx|j�}y
|dkrdn||||}Wntk
r<|SX||kr`d|}d|}||}}|||||dS)z�Triangular
distribution.

        Continuous distribution bounded by given lower and upper limits,
        and having a given mode value in-between.

        http://en.wikipedia.org/wiki/Triangular_distribution

       
Ng�?g�?)r�ZeroDivisionError)r/ZlowZhigh�mode�urHr1r1r2r
ys	 
zRandom.triangularcCsT|j}x@|�}d|�}t|d|}||d}|t|�krPqW|||S)z\Normal
distribution.

        mu is the mean, and sigma is the standard deviation.

       
g�?g�?g@)r�
NV_MAGICCONSTrp)r/�mu�sigmar�u1�u2�zZzzr1r1r2r�s

zRandom.normalvariatecCst|j||��S)z�Log normal
distribution.

        If you take the natural logarithm of this distribution, you'll
get a
        normal distribution with mean mu and standard deviation sigma.
        mu can have any value, and sigma must be greater than zero.

       
)�_expr)r/r�r�r1r1r2r�szRandom.lognormvariatecCstd|j��|S)a^Exponential
distribution.

        lambd is 1.0 divided by the desired mean.  It should be
        nonzero.  (The parameter would be called "lambda", but
that is
        a reserved word in Python.)  Returned values range from 0 to
        positive infinity if lambd is positive, and from negative
        infinity to 0 if lambd is negative.

       
g�?)rpr)r/Zlambdr1r1r2r�szRandom.expovariatecCs�|j}|dkrt|�Sd|}|td||�}xN|�}tt|�}|||}|�}	|	d||ks~|	d|t|�kr6Pq6Wd|}
|
|d|
|}|�}|dkr�|t|�t}
n|t|�t}
|
S)aFCircular
data distribution.

        mu is the mean angle, expressed in radians between 0 and 2*pi, and
        kappa is the concentration parameter, which must be greater than or
        equal to zero.  If kappa is equal to zero, this distribution
reduces
        to a uniform random angle over the range 0 to 2*pi.

       
g���ư>g�?g�?)r�TWOPI�_sqrt�_cos�_pir��_acos)r/r�Zkappar�srbr�r��dr��q�fZu3Zthetar1r1r2r�s&
$zRandom.vonmisesvariatecCs�|dks|dkrtd��|j}|dkr�td|d�}|t}||}x�|�}d|ko`dknshqHd|�}t|d|�|}	|t|	�}
|||}|||	|
}|td|dks�|t|�krH|
|SqHWn�|dk�r|�}
x|
dk�r|�}
q�Wt|
�|Sx�|�}
t|t}||
}|dk�rD|d|}
nt|||�}
|�}|dk�r|||
|dk�r�Pn|t|
�k�rP�qW|
|SdS)	aZGamma distribution.  Not the gamma function!

        Conditions on the parameters are alpha > 0 and beta > 0.

        The probability distribution function is:

                    x ** (alpha - 1) * math.exp(-x / beta)
          pdf(x) =  --------------------------------------
                      math.gamma(alpha) * beta ** alpha

        gz*gammavariate: alpha and beta must be >
0.0g�?g@gH�����z>g�P���?g@N)rOrr��LOG4rpr��
SG_MAGICCONST�_e)r/�alpha�betarZainvZbbbZcccr�r��vr0r�rbr�r\�pr1r1r2r�sJ
 



zRandom.gammavariatecCs`|j}|j}d|_|dkrT|�t}tdtd|���}t|�|}t|�||_|||S)z�Gaussian
distribution.

        mu is the mean, and sigma is the standard deviation.  This is
        slightly faster than the normalvariate() function.

        Not thread-safe without a lock around calls.

       
Ng@g�?g�)rr.r�r�rpr��_sin)r/r�r�rr�Zx2piZg2radr1r1r2r!?s
zRandom.gausscCs0|j|d�}|dkrdS|||j|d�SdS)z�Beta
distribution.

        Conditions on the parameters are alpha > 0 and beta > 0.
        Returned values range between 0 and 1.

        g�?rgN)r)r/r�r��yr1r1r2r"ts
zRandom.betavariatecCsd|j�}d|d|S)z3Pareto
distribution.  alpha is the shape
parameter.g�?)r)r/r�r�r1r1r2r#�szRandom.paretovariatecCs"d|j�}|t|�d|S)zfWeibull
distribution.

        alpha is the scale parameter and beta is the shape parameter.

       
g�?)rrp)r/r�r�r�r1r1r2r$�szRandom.weibullvariate)N)Nr,)N)N)r~rN)$�__name__�
__module__�__qualname__�__doc__rJr3rr%r&rRrSrTrCrr�BPFr`�_MethodType�_BuiltinMethodTyperUrrrr(rr
rrrrrr!r"r#r$�
__classcell__r1r1)rIr2rGs8
	 ,

:
0H5	c@s8eZdZdZdd�Zdd�Zdd�Zdd	�ZeZZ	d
S)r)z�Alternate random number generator using sources provided
    by the operating system (such as /dev/urandom on Unix or
    CryptGenRandom on Windows).

     Not available on all systems (see os.urandom() for details).
    cCstjtd�d�d?tS)z3Get the next random number in the
range [0.0,
1.0).r5r6r-)rCrD�_urandom�	RECIP_BPF)r/r1r1r2r�szSystemRandom.randomcCsP|dkrtd��|t|�kr$td��|dd}tjt|�d�}||d|?S)z:getrandbits(k)
-> x.  Generates an int with k random bits.rz(number of bits must be
greater than zeroz#number of bits should be an
integerr5�r6)rOrCrPrDr�)r/raZnumbytesr0r1r1r2r'�szSystemRandom.getrandbitscOsdS)z<Stub
method.  Not used for a system random number
generator.Nr1)r/�args�kwdsr1r1r2r�szSystemRandom.seedcOstd��dS)zAMethod
should not be called for a system random number generator.z*System entropy
source does not have
state.N)�NotImplementedError)r/r�r�r1r1r2�_notimplemented�szSystemRandom._notimplementedN)
r�r�r�r�rr'rr�r%r&r1r1r1r2r)�s
cCs�ddl}t|d|j�d}d}d}d
}|j�}x@t|�D]4}	||�}
||
7}||
|
}t|
|�}t|
|�}q8W|j�}tt||d�ddd�||}t||||�}
td	||
||f�dS)Nr�timesgg
_�Br-zsec,� )�endz"avg %g, stddev %g, min %g, max %g
g
_��)�time�printr�rh�min�max�roundr�)r[�funcr�r�rwZsqsumZsmallestZlargestZt0rfr0Zt1ZavgZstddevr1r1r2�_test_generator�s&
r���cCs�t|tf�t|td�t|td�t|td
�t|td�t|td�t|td�t|td�t|td�t|td�t|td�t|td�t|td�t|td�t|td�t|td�dS)N���?�{�G�z�?皙�����?�@��?��������?�4@�i@�@)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r�)r�r��UUUUUU�?)r�r�r�)	r�rrrrrr!r"r
)�Nr1r1r2�_test�s
r��__main__g�)r�)Or��warningsrr^�typesrr�rr�Zmathrrprr�rr�rr�r	ror
r�rr�rr�r
r��osrr��_collections_abcrrmrrnZhashlibrrB�	itertoolsr{ryr}�__all__r�r�r�r�r�r�Z_randomrr)r�r�Z_instrrrr
rrrrrr(rrrrrr!r"r#r$r%r&r'r�r1r1r1r2�<module>&sn
Y!