Your IP : 18.223.108.134


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/random.cpython-310.pyc

o

6��fŁ�@sdZddlmZddlmZmZm	Z
mZm
ZddlmZmZmZmZddlmZmZmZddlmZddl m!Z"m#Z$ddl%m&Z'dd	l(m)Z*m+Z,dd
l-m-Z.ddlZ/ddl0Z0zddl1m2Z1Wne3ymddl4m2Z1Ynwgd
�Z5ded�ed�Z6ed�Z7ded�Z8dZ9de9Z:dZ;Gdd�de0j<�Z<Gdd�de<�Z=e<�Z>e>j?Z?e>j@Z@e>jAZAe>jBZBe>jCZCe>jDZDe>jEZEe>jFZFe>jGZGe>jHZHe>jIZIe>jJZJe>jKZKe>jLZLe>jMZMe>jNZNe>jOZOe>jPZPe>jQZQe>jRZRe>jSZSe>jTZTe>jUZUdd�ZVd#dd�ZWeXe/d �r�e/jYe>j?d!�eZd"k�reW�dSdS)$a�Random variable generators.

    bytes
    -----
           uniform bytes (values between 0 and 255)

    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)�tau�floor�isfinite)�urandom)�Set�Sequence)�index)�
accumulate�repeat)�bisectN)�sha512)�Random�SystemRandom�betavariate�choice�choices�expovariate�gammavariate�gauss�getrandbits�getstate�lognormvariate�
normalvariate�
paretovariate�	randbytes�randint�random�	randrange�sample�seed�setstate�shuffle�
triangular�uniform�vonmisesvariate�weibullvariate�g��@�@��?�@�5��cs.eZdZdZdZdBdd�ZdC�fdd�	Z�fd	d
�Z�fdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
de>fdd�Ze
Zdd�Zdefdd�Zdd�Zd d!�ZdBd"d#�Zdd$�d%d&�ZdBddd'�d(d)�Zd*d+�ZdDd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#�Z$S)Era�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�r<�-/opt/alt/python310/lib64/python3.10/random.py�__init__ws

zRandom.__init__r6cs|dkrBt|ttf�rBt|t�r|�d�n|}|r!t|d�d>nd}tt|�D]
}d||Ad@}q(|t|�N}|dkr?dn|}n5|d	krdt|tttf�rdt|t�rW|��}t	�
|t|���d
�}nt|t
d�t	ttttf�swtdtd	�t��|�d|_dS)
a\Initialize internal state from a seed.

        The only supported seed types are None, int, float,
        str, bytes, and bytearray.

        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.

        r7zlatin-1r�iCBl����������r6�bigNz�Seeding based on hashing is deprecated
since Python 3.9 and will be removed in a subsequent version. The only 
supported seed types are: None, int, float, str, bytes, and bytearray.)�
isinstance�str�bytes�decode�ord�map�len�	bytearray�encode�int�
from_bytes�_sha512Zdigest�type�float�_warn�DeprecationWarning�superr)r9)r:�a�versionr;�c��	__class__r<r=r)�s"
�
zRandom.seedcs|jt���|jfS)z9Return internal state; can be passed to setstate() later.)�VERSIONrSr r9�r:rWr<r=r ��zRandom.getstatec
s�|d}|dkr|\}}|_t��|�dS|dkrC|\}}|_ztdd�|D��}Wnty:}zt|�d}~wwt��|�dStd||jf��)z:Restore internal state from object returned by getstate().rr8r6css�|]}|dVqdS)lNr<)�.0r;r<r<r=�	<genexpr>�s�z"Random.setstate.<locals>.<genexpr>Nz?state with version %s passed to Random.setstate() of version %s)r9rSr*�tuple�
ValueError�	TypeErrorrY)r:�staterUZ
internalstaterrWr<r=r*�s ���zRandom.setstatecCs|��S�N)r rZr<r<r=�__getstate__�szRandom.__getstate__cCs|�|�dSrb)r*)r:rar<r<r=�__setstate__�szRandom.__setstate__cCs|jd|��fS)Nr<)rXr rZr<r<r=�
__reduce__�szRandom.__reduce__cKsP|jD]"}d|jvr
dSd|jvr|j|_dSd|jvr%|j|_dSqdS)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.
        �
_randbelowrr&N)�__mro__�__dict__�_randbelow_with_getrandbitsrf�_randbelow_without_getrandbits)�cls�kwargsrVr<r<r=�__init_subclass__�s
	


��zRandom.__init_subclass__cCs:|sdS|j}|��}||�}||kr||�}||ks|S)z;Return a random int in the range [0,n).  Returns 0 if n==0.r)r�
bit_length)r:�nr�k�rr<r<r=ri�s�z"Random._randbelow_with_getrandbitsr7cCsp|j}||krtd�t|�|�S|dkrdS||}|||}|�}||kr0|�}||ks)t||�|S)z�Return a random int in the range [0,n).  Returns 0 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.r)r&rQ�_floor)r:ro�maxsizer&Zrem�limitrqr<r<r=rj�s�z%Random._randbelow_without_getrandbitscCs|�|d��|d�S)�Generate n random bytes.��little)r�to_bytes�r:ror<r<r=r$szRandom.randbytesc	Cs�zt|�}Wn!ty't|�}||krtdtd�td��tdtd�Ynw|durA|tur4td��|dkr=|�|�Std��zt|�}Wn!tyht|�}||kr`tdtd�td	��tdtd�Ynw||}zt|�}Wn!ty�t|�}||kr�tdtd�td
��tdtd�Ynw|dkr�|dkr�||�|�Std|||f��|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.randrange() will raise TypeError in the futurer6z!non-integer arg 1 for randrange()zwnon-integer arguments to randrange() have been deprecated since Python 3.10 and will be removed in a subsequent versionNz Missing a non-None stop argumentrzempty range for randrange()z non-integer stop for randrange()z non-integer step for randrange()r7z(empty range for randrange() (%d, %d, %d)zzero step for randrange())�_indexr`rLrQrRr_�_ONErf)	r:�start�stop�stepZistartZistop�widthZistepror<r<r=r'$st
���

���
���zRandom.randrangecCs|�||d�S)zJReturn random integer in range [a, b], including both end points.
        r7)r'�r:rT�br<r<r=r%nszRandom.randintcCs||�t|��S)z2Choose a random element from a non-empty sequence.)rfrI)r:�seqr<r<r=rwsz
Random.choicecCs�|dur(|j}ttdt|���D]}||d�}||||||<||<qdStdtd�t}ttdt|���D]}||�|d�}||||||<||<q9dS)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.

        Nr7zuThe *random* parameter to shuffle() has been deprecated
since Python 3.9 and will be removed in a subsequent version.r6)rf�reversed�rangerIrQrRrr)r:r;r&�	randbelow�i�jr
r<r<r=r+|s	���zRandom.shuffle)�countscs�t�t�st�t�rtdtd�t���ntd��t��}|dur\tt	|���t��|kr1t
d�����}t|t�s>td��|dkrFt
d��|j
t|�|d	�}t����fd
d�|D�S|j}d|krl|ksqt
d��t
d��dg|}d
}	|dkr�|	dtt|dd��7}	||	kr�t��}
t|�D]}|||�}|
|||<|
||d|
|<q�|St�}
|
j}t|�D]}||�}||
vr�||�}||
vs�||��|||<q�|S)amChooses 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.

        Repeated elements can be specified one at a time or with the optional
        counts parameter.  For example:

            sample(['red', 'blue'], counts=[4, 2], k=5)

        is equivalent to:

            sample(['red', 'red', 'red', 'red', 'blue', 'blue'], k=5)

        To choose a sample from a range of integers, use range() for the
        population argument.  This is especially fast and space efficient
        for sampling from a large population:

            sample(range(10000000), 60)

        z\Sampling from a set deprecated
since Python 3.9 and will be removed in a subsequent version.r6zAPopulation must be a sequence.  For dicts or sets, use sorted(d).Nz2The number of counts does not match the populationzCounts must be integersrz)Total of counts must be greater than zero)rpcsg|]	}���|��qSr<r<)r\�s�rZ
cum_counts�
populationr<r=�
<listcomp>�sz!Random.sample.<locals>.<listcomp>z,Sample larger than population or is negative��r0r8r7)rC�	_Sequence�_SetrQrRr^r`rI�list�_accumulater_�poprLr(r��_bisectrf�_ceil�_log�set�add)r:r�rpr�ro�totalZ
selectionsr��resultZsetsizeZpoolr�r�ZselectedZselected_addr<r�r=r(�s\
5
�

�

��z
Random.sample)�cum_weightsrpcs|j�t����durD|dur$t��d7�����fdd�td|�D�Sztt|���WntyCt|t�s9�|}td|���d�w|durLtd��t���krVt	d���dd��dkrdt	d	��t
��slt	d
��t��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|]}�������qSr<r<�r\r�)r
ror�r&r<r=r�sz"Random.choices.<locals>.<listcomp>z4The number of choices must be a keyword argument: k=z2Cannot specify both weights and cumulative weightsz3The number of weights does not match the populationr@z*Total of weights must be greater than zerozTotal of weights must be finiter7cs$g|]}������d���qS)rr<r�)rr��hir�r&r�r<r=r�s�)r&rIrr�_repeatr�r�r`rCrLr_�	_isfiniter�)r:r�Zweightsr�rpr<)rr�r
r�ror�r&r�r=r�sB
����zRandom.choicescCs||||��S)zHGet a random number in the range [a, b) or [a, b] depending on rounding.�r&r�r<r<r=r-"r[zRandom.uniformr�r3cCsz|��}z|durdn||||}Wnty|YSw||kr1d|}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��?r3)r&�ZeroDivisionError�_sqrt)r:�low�high�mode�urVr<r<r=r,&s	 �
zRandom.triangularcCsR|j}	|�}d|�}t|d|}||d}|t|�kr"nq|||S)z\Normal distribution.

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

        Tr3r�r2)r&�
NV_MAGICCONSTr�)r:�mu�sigmar&�u1�u2�zZzzr<r<r=r":s
�zRandom.normalvariatecCs`|j}|j}d|_|dur*|�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�r3)r&r9�TWOPIr�r��_cos�_sin)r:r�r�r&r�Zx2piZg2radr<r<r=rOs
zRandom.gausscCst|�||��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�r<r<r=r!uszRandom.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.

        r3)r�r&)r:Zlambdr<r<r=rszRandom.expovariatecCs�|j}|dkrt|�Sd|}|td||�}	|�}tt|�}|||}|�}	|	d||ks?|	d|t|�kr@nqd|}
|
|d|
|}|�}|dkr`|t|�t}
|
S|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�r3)r&r�r�r��_pir��_acos)r:r�Zkappar&r�rqr�r��dr��q�fZu3Zthetar<r<r=r.�s*
$�	�zRandom.vonmisesvariatecCsz|dks|dkrtd��|j}|dkrktd|d�}|t}||}	|�}d|kr1dks3nq#d|�}t|d|�|}	|t|	�}
|||}|||	|
}|td|dksf|t|�krj|
|Sq$|dkrytd|��|S	|�}
t|t}||
}|dkr�|d|}
n	t|||�}
|�}|dkr�||
|dkr�	|
|Sn|t|
�kr�	|
|Sqz)	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.0r3r1TgH�����z>g�P���?r4)r_r&r��LOG4r�r��
SG_MAGICCONST�_e)r:�alpha�betar&ZainvZbbbZcccr�r��vr;r�rqr�r��pr<r<r=r�sL
 ���zRandom.gammavariatecCs(|�|d�}|r|||�|d�SdS)z�Beta distribution.

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

        r3r�)r)r:r�r��yr<r<r=r�szRandom.betavariatecCsd|��}|d|S)z3Pareto distribution.  alpha is the shape parameter.r3g�r�)r:r�r�r<r<r=r#szRandom.paretovariatecCs"d|��}|t|�d|S)zfWeibull distribution.

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

        r3)r&r�)r:r�r�r�r<r<r=r/szRandom.weibullvariaterb)Nr6)r�r3N)%�__name__�
__module__�__qualname__�__doc__rYr>r)r r*rcrdrermri�BPFrjrfr$r{r'r%rr+r(rr-r,r"rr!rr.rrr#r/�
__classcell__r<r<rWr=rgs@
	*!
J	
d(
&
*Arc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZeZ	Z
dS)
rz�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).r?rBr8)rLrM�_urandom�	RECIP_BPFrZr<r<r=r&6szSystemRandom.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 non-negativer?rvrB)r_rLrMr�)r:rpZnumbytesr;r<r<r=r:s
zSystemRandom.getrandbitscCst|�S)ru)r�ryr<r<r=r$BszSystemRandom.randbytescOsdS)z<Stub method.  Not used for a system random number generator.Nr<�r:�args�kwdsr<r<r=r)HszSystemRandom.seedcOstd��)zAMethod should not be called for a system random number generator.z*System entropy source does not have state.)�NotImplementedErrorr�r<r<r=�_notimplementedLszSystemRandom._notimplementedN)r�r�r�r�r&rr$r)r�r r*r<r<r<r=r-src
s�ddlm}m}ddlm}|�}��fdd�td|�D�}|�}||�}	|||	�}
t|�}t|�}t||d�d|�d�j	���td	|	|
||f�dS)
Nr)�stdev�fmean)�perf_countercsg|]}����qSr<r<r��r��funcr<r=r�{sz#_test_generator.<locals>.<listcomp>z.3fz sec, z times z"avg %g, stddev %g, min %g, max %g
)
Z
statisticsr�r��timer�r��min�max�printr�)
ror�r�r�Zmeanr�Zt0�data�t1Zxbarr�r�r�r<r�r=�_test_generatorvs
 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)Nr<)r�r3)g{�G�z�?r3)皙�����?r3)r�r1)r�r3)g�������?r3)r3r3)r1r3)g4@r3)gi@r3)�@r�)r�r3gUUUUUU�?)	r�r&r"r!r.rrrr,)�Nr<r<r=�_test�s r��fork)Zafter_in_child�__main__)r�)[r��warningsrrQZmathrr�rr�rr�rr�rr�rr�r	r�r
r�rr�rr�r
rrrr��osrr��_collections_abcrr�rr��operatorrrz�	itertoolsrr�rr�rr��_osZ_randomrNr�ImportErrorZhashlib�__all__r�r�r�r�r�r{rrZ_instr)r&r-r,r%rr'r(r+rr"r!rr.rrrr#r/r r*rr$r�r��hasattr�register_at_forkr�r<r<r<r=�<module>s|/�
K,



�

?>