AlkantarClanX12

Your IP : 3.21.247.78


Current Path : /usr/lib64/python3.8/__pycache__/
Upload File :
Current File : //usr/lib64/python3.8/__pycache__/random.cpython-38.pyc

U

e5d�p�@sdZddlmZddlmZmZm	Z
mZm
ZddlmZmZmZmZddlmZddlmZmZddlm Z!m"Z#ddl$m$Z%dd	lZ&zdd
l'm(Z'Wn e)k
r�dd
l*m(Z'YnXddd
ddddddddddddddddddd d!d"gZ+d#ed$�ed%�Z,d%e
Z-ed&�Z.d'ed(�Z/d)Z0d*e0Z1dd	l2Z2Gd+d�de2j3�Z3Gd,d"�d"e3�Z4d-d.�Z5d5d0d1�Z6e3�Z7e7j8Z8e7j9Z9e7j:Z:e7j;Z;e7j<Z<e7j=Z=e7j>Z>e7j?Z?e7j@Z@e7jAZAe7jBZBe7jCZCe7jDZDe7jEZEe7jFZFe7jGZGe7jHZHe7jIZIe7jJZJe7jKZKe7jLZLe7jMZMeNe&d2��re&jOe7j8d3�ePd4k�re6�d	S)6a�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)�log�exp�pi�e�ceil)�sqrt�acos�cos�sin)�urandom)�Set�Sequence)�
accumulate�repeat)�bisectN)�sha512�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��@�@��?�@�5�cs$eZdZdZdZd?dd�Zdd�Zd@�fd	d
�	Z�fdd�Z�fd
d�Z	dd�Z
dd�Zdd�Zdde
fdd�Zdd�Zdd�Ze
de>fdd�ZeZdd�ZdAd d!�Zd"d#�ZdBddd$�d%d&�Zd'd(�ZdCd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Z d;d<�Z!d=d>�Z"�Z#S)Dra�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|�|�d|_dS)zeInitialize an instance.

        Optional argument x controls seeding, as for Random.seed().
        N)r�
gauss_next)�self�x�r6�/usr/lib64/python3.8/random.py�__init__^s
zRandom.__init__cKsJ|jD]>}d|jkrqFd|jkr.|j|_qFd|jkr|j|_qFqdS)aControl how subclasses generate random integers.

        The algorithm a subclass can use depends on the random() and/or
        getrandbits() implementation available to it and determines
        whether it can generate random integers from arbitrarily large
        ranges.
        �
_randbelowr(rN)�__mro__�__dict__�_randbelow_with_getrandbitsr9�_randbelow_without_getrandbits)�cls�kwargs�cr6r6r7�__init_subclass__gs	



zRandom.__init_subclass__r1cs�|dkr�t|ttf�r�t|t�r*|�d�n|}|rBt|d�d>nd}tt|�D]}d||Ad@}qP|t|�N}|dkr~dn|}|d	kr�t|tttf�r�t|t�r�|��}|t	|��
�7}t�|d
�}t
��|�d|_dS)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����������r1�bigN)�
isinstance�str�bytes�decode�ord�map�len�	bytearray�encode�_sha512Zdigest�int�
from_bytes�superrr3)r4�a�versionr5r@��	__class__r6r7r{s
zRandom.seedcs|jt���|jfS)z9Return internal state; can be passed to setstate() later.)�VERSIONrSr&r3�r4rVr6r7r&�szRandom.getstatec
s�|d}|dkr*|\}}|_t��|�nt|dkr�|\}}|_ztdd�|D��}Wn(tk
r|}z
t|�W5d}~XYnXt��|�ntd||jf��dS)z:Restore internal state from object returned by getstate().rr2r1css|]}|dVqdS)lNr6)�.0r5r6r6r7�	<genexpr>�sz"Random.setstate.<locals>.<genexpr>Nz?state with version %s passed to Random.setstate() of version %s)r3rSr'�tuple�
ValueError�	TypeErrorrX)r4�staterUZ
internalstaterrVr6r7r'�s�zRandom.setstatecCs|��S�N)r&rYr6r6r7�__getstate__�szRandom.__getstate__cCs|�|�dSr`)r')r4r_r6r6r7�__setstate__�szRandom.__setstate__cCs|jd|��fS)Nr6)rWr&rYr6r6r7�
__reduce__�szRandom.__reduce__rBc
Cs||�}||krtd��|dkr:|dkr2|�|�Std��||�}||krRtd��||}|dkrx|dkrx||�|�S|dkr�td|||f��||�}||kr�td��|dkr�||d|}	n"|dkr�||d|}	ntd	��|	dkr�td��|||�|	�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()rBz(empty range for randrange() (%d, %d, %d)z non-integer step for randrange()zzero step for randrange())r]r9)
r4�start�stop�step�_intZistartZistop�widthZistep�nr6r6r7r�s4

zRandom.randrangecCs|�||d�S)zJReturn random integer in range [a, b], including both end points.
        rB)r�r4rT�br6r6r7r�szRandom.randintcCs,|j}|��}||�}||kr(||�}q|S)zCReturn a random int in the range [0,n).  Raises ValueError if n==0.)r(�
bit_length)r4rir(�k�rr6r6r7r<�s
z"Random._randbelow_with_getrandbitscCsn|j}||kr$td�||�|�S|dkr4td��||}|||}|�}||kr^|�}qN|||�|S)z�Return a random int in the range [0,n).  Raises ValueError if n==0.

        The implementation does not use getrandbits, but only random.
        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)r�_warnr])r4rirQ�maxsizerZrem�limitrnr6r6r7r=sz%Random._randbelow_without_getrandbitscCs:z|�t|��}Wntk
r0td�d�YnX||S)z2Choose a random element from a non-empty sequence.z$Cannot choose from an empty sequenceN)r9rMr]�
IndexError)r4�seq�ir6r6r7rs
z
Random.choicecCs�|dkrN|j}ttdt|���D]*}||d�}||||||<||<q nHt}ttdt|���D]0}||�|d�}||||||<||<qddS)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.

        NrB)r9�reversed�rangerMrQ)r4r5r�	randbelowrt�jrgr6r6r7r%s	zRandom.shufflecCst|t�rt|�}t|t�s$td��|j}t|�}d|krF|ksPntd��dg|}d}|dkr�|dtt	|dd��7}||kr�t
|�}t|�D]0}|||�}	||	||<|||d	||	<q�nHt�}
|
j
}t|�D]2}||�}	|	|
kr�||�}	q�||	�||	||<q�|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+r2rB)rG�_Setr\�	_Sequencer^r9rMr]�_ceil�_log�listrv�set�add)r4�
populationrmrwri�resultZsetsizeZpoolrtrxZselectedZselected_addr6r6r7r;s6)



z
Random.sample)�cum_weightsrmcs�|j�t����dkrV|dkrHt��d7�����fdd�td|�D�Stt|���n|dk	rftd��t���krztd��t��dd��d�������fd	d�td|�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.

        N�csg|]}�������qSr6r6�rZrt)rgrir�rr6r7�
<listcomp>�sz"Random.choices.<locals>.<listcomp>z2Cannot specify both weights and cumulative weightsz3The number of weights does not match the populationrDrBcs$g|]}������d���qS)rr6r�)rr��hir�r�totalr6r7r��s�)	rrMrQ�_repeatr�_accumulater^r]�_bisect)r4r�Zweightsr�rmr6)rgrr�r�rir�rr�r7r)�s$�zRandom.choicescCs||||��S)zHGet a random number in the range [a, b) or [a, b] depending on rounding.�rrjr6r6r7r�szRandom.uniformr�r.cCs||��}z |dkrdn||||}Wntk
r@|YSX||krdd|}d|}||}}|||t||�S)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

        N��?r.)r�ZeroDivisionError�_sqrt)r4ZlowZhigh�mode�ur@r6r6r7r!�s	 

zRandom.triangularcCsP|j}|�}d|�}t|d|}||d}|t|�krqDq|||S)z\Normal distribution.

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

        r.r�r-)r�
NV_MAGICCONSTr~)r4�mu�sigmar�u1�u2�zZzzr6r6r7r�s

zRandom.normalvariatecCst|�||��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)r4r�r�r6r6r7r�szRandom.lognormvariatecCstd|���|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.

        r.)r~r)r4Zlambdr6r6r7r�szRandom.expovariatecCs�|j}|dkrt|�Sd|}|td||�}|�}tt|�}|||}|�}	|	d||ks�|	d|t|�kr4q�q4d|}
|
|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���ư>r�r.)r�TWOPIr��_cos�_pir��_acos)r4r�Zkappar�srnr�r��dr��q�fZu3Zthetar6r6r7r�s$
$zRandom.vonmisesvariatecCs~|dks|dkrtd��|j}|dkr�td|d�}|t}||}|�}d|kr`dksdqFqFd|�}t|d|�|}	|t|	�}
|||}|||	|
}|td|dks�|t|�krF|
|SqFn�|dkr�td|��|S|�}
t|t}||
}|dk�r$|d|}
nt|||�}
|�}|dk�r^||
|dk�rp�qrq�|t|
�kr�qrq�|
|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

        r�z*gammavariate: alpha and beta must be > 0.0r.r,gH�����z>g�P���?r/N)r]rr��LOG4r~r��
SG_MAGICCONST�_e)r4�alpha�betarZainvZbbbZcccr�r��vr5r�rnr�rk�pr6r6r7r #s@
 

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�r.)rr3r�r�r~r��_sin)r4r�r�rr�Zx2piZg2radr6r6r7r"hs
zRandom.gausscCs0|�|d�}|dkrdS|||�|d�SdS)z�Beta distribution.

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

        r.rr�N)r )r4r�r��yr6r6r7r#�s
zRandom.betavariatecCsd|��}d|d|S)z3Pareto distribution.  alpha is the shape parameter.r.r�)r4r�r�r6r6r7r$�szRandom.paretovariatecCs"d|��}|t|�d|S)zfWeibull distribution.

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

        r.)rr~)r4r�r�r�r6r6r7r%�szRandom.weibullvariate)N)Nr1)N)N)r�r.N)$�__name__�
__module__�__qualname__�__doc__rXr8rArr&r'rarbrcrQrrr<�BPFr=r9rrrr)rr!rrrrr r"r#r$r%�
__classcell__r6r6rVr7rNs<

	 ,

G
0E5	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).
    cCst�td�d�d?tS)z3Get the next random number in the range [0.0, 1.0).rCrFr2)rQrR�_urandom�	RECIP_BPFrYr6r6r7r�szSystemRandom.randomcCs<|dkrtd��|dd}t�t|�d�}||d|?S)z:getrandbits(k) -> x.  Generates an int with k random bits.rz(number of bits must be greater than zerorC�rF)r]rQrRr�)r4rmZnumbytesr5r6r6r7r(�s
zSystemRandom.getrandbitscOsdS)z<Stub method.  Not used for a system random number generator.Nr6�r4�args�kwdsr6r6r7r�szSystemRandom.seedcOstd��dS)zAMethod should not be called for a system random number generator.z*System entropy source does not have state.N)�NotImplementedErrorr�r6r6r7�_notimplemented�szSystemRandom._notimplementedN)
r�r�r�r�rr(rr�r&r'r6r6r6r7r*�scCs�ddl}t|d|j�d}d}d}d}|��}t|�D]4}	||�}
||
7}||
|
}t|
|�}t|
|�}q6|��}tt||d�ddd	�||}t||||�}
td
||
||f�dS)Nr�timesr�g _�Bg _��r2zsec,� )�endz"avg %g, stddev %g, min %g, max %g
)	�time�printr��perf_counterrv�min�max�roundr�)ri�funcr�r�r�ZsqsumZsmallestZlargestZt0rtr5�t1ZavgZstddevr6r6r7�_test_generator�s(

�r���cCs�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�t|td
�dS)Nr6)r�r.)g{�G�z�?r.)皙�����?r.)r�r,)r�r.)g�������?r.)r.r.)r,r.)g4@r.)gi@r.)�@r�)r�r.gUUUUUU�?)	r�rrrrr r"r#r!)�Nr6r6r7�_test�s r��fork)Zafter_in_child�__main__)r�)Qr��warningsrroZmathrr~rr�rr�rr�rr}rr�r	r�r
r�rr��osrr��_collections_abcr
r{rr|�	itertoolsrr�rr�rr��_osrPr�ImportErrorZhashlib�__all__r�r�r�r�r�r�Z_randomrr*r�r�Z_instrrrr!rrrrrr)rrrrr r"r#r$r%r&r'r(�hasattr�register_at_forkr�r6r6r6r7�<module>s�'�
{