Hacked By AnonymousFox

Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/random.cpython-35.opt-1.pyc



��Yf_g�@s|dZddlmZddlmZmZddl	m
ZmZ
mZmZmZddl	mZmZmZmZddlmZddlm Z!m"Z#ddl$m%Z&d	d
ddd
ddddddddddddddddddgZ'd e
d!�ed"�Z(d"eZ)ed#�Z*d$ed%�Z+d&Z,d'e,Z-dd(l.Z.Gd)d	�d	e.j/�Z/Gd*d�de/�Z0d+d,�Z1d-d.d/�Z2e/�Z3e3j4Z4e3j5Z5e3j6Z6e3j7Z7e3j8Z8e3j9Z9e3j:Z:e3j;Z;e3j<Z<e3j=Z=e3j>Z>e3j?Z?e3j@Z@e3jAZAe3jBZBe3jCZCe3jDZDe3jEZEe3jFZFe3jGZGe3jHZHeId0krxe2�d(S)1a�Random variable generators.

    integers
    --------
           uniform within range

    sequences
    ---------
           pick random element
           pick 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)�sha512�Random�seed�random�uniform�randint�choice�sample�	randrange�shuffle�
normalvariate�lognormvariate�expovariate�vonmisesvariate�gammavariate�
triangular�gauss�betavariate�
paretovariate�weibullvariate�getstate�setstate�getrandbits�SystemRandom�g�?g@g@g�?g@�5�NcseZdZdZdZddd�Zdd�fdd�Z�fd	d
�Z�fdd�Zd
d�Z	dd�Z
dd�Zddedd�Z
dd�Zede>eeedd�Zdd�Zddd�Zdd�Zd d!�Zd"d#dd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Z d6d7�Z!�S)8ra�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�r0�+/opt/alt/python35/lib64/python3.5/random.py�__init__Ts
zRandom.__init__r+c
su|dkr_ytjtd�d�}Wn4tk
r^ddl}t|j�d�}YnX|dkr�t|ttf�r�|r�t|d�d>nd}x&|D]}d|t|�Ad	@}q�W|t	|�N}|dkr�dn|}|d
krXt|ttt
f�rXt|t�r0|j�}|t|�j
�7}tj|d�}t�j|�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.

        Ni�	�bigr���iCBl����r+������)�int�
from_bytes�_urandom�NotImplementedError�time�
isinstance�str�bytes�ord�len�	bytearray�encode�_sha512Zdigest�superrr-)r.�a�versionr=r/�c)�	__class__r0r1r]s(
! 
zRandom.seedcs|jt�j�|jfS)z9Return internal state; can be passed to setstate() later.)�VERSIONrFr%r-)r.)rJr0r1r%�szRandom.getstatecs�|d}|dkr;|\}}|_t�j|�n�|dkr�|\}}|_ytdd�|D��}Wn.tk
r�}zt|�WYdd}~XnXt�j|�ntd||jf��dS)z:Restore internal state from object returned by getstate().rr,r+css|]}|dVqdS)r+� Nlr0)�.0r/r0r0r1�	<genexpr>�sz"Random.setstate.<locals>.<genexpr>Nz?state with version %s passed to Random.setstate() of version %s)r-rFr&�tuple�
ValueError�	TypeErrorrK)r.�staterHZ
internalstater)rJr0r1r&�s
zRandom.setstatecCs
|j�S)N)r%)r.r0r0r1�__getstate__�szRandom.__getstate__cCs|j|�dS)N)r&)r.rRr0r0r1�__setstate__�szRandom.__setstate__cCs|jf|j�fS)N)rJr%)r.r0r0r1�
__reduce__�szRandom.__reduce__r5c
Csp||�}||kr$td��|dkrU|dkrI|j|�Std��||�}||krytd��||}|dkr�|dkr�||j|�S|dkr�td|||f��||�}||kr�td��|dkr||d|}	n-|dkr7||d|}	ntd	��|	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()r5z'empty range for randrange() (%d,%d, %d)z non-integer step for randrange()zzero step for randrange())rP�
_randbelow)
r.�start�stop�step�_intZistartZistop�widthZistep�nr0r0r1r�s4


zRandom.randrangecCs|j||d�S)zJReturn random integer in range [a, b], including both end points.
        r5)r)r.rG�br0r0r1r�szRandom.randintc
Cs�|j}|j}||�|ks6||�|krq|j�}	||	�}
x|
|krl||	�}
qQW|
S||kr�td�||�|�S||}|||}|�}
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.)rr'�
bit_length�_warn)
r.r\r9�maxsize�typeZMethodZ
BuiltinMethodrr'�k�rZrem�limitr0r0r1rV�s"		$

	
zRandom._randbelowcCsBy|jt|��}Wntk
r9td��YnX||S)z2Choose a random element from a non-empty sequence.z$Cannot choose from an empty sequence)rVrBrP�
IndexError)r.�seq�ir0r0r1rs

z
Random.choicecCs�|dkrk|j}x�ttdt|���D]3}||d�}||||||<||<q1Wn`t}xWttdt|���D]:}||�|d�}||||||<||<q�WdS)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.

        Nr5)rV�reversed�rangerBr9)r.r/r�	randbelowrg�jrZr0r0r1rs		"$"zRandom.shufflecCs�t|t�rt|�}t|t�s6td��|j}t|�}d|kob|knsstd��dg|}d}|dkr�|dtt	|dd��7}||krt
|�}x�t|�D]:}|||�}	||	||<|||d	||	<q�Wnlt�}
|
j
}xWt|�D]I}||�}	x|	|
krh||�}	qMW||	�||	||<q8W|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).rzSample larger than populationN��r)r,r5)r>�_SetrO�	_SequencerQrVrBrP�_ceil�_log�listri�set�add)r.Z
populationrbrjr\�resultZsetsizeZpoolrgrkZselectedZselected_addr0r0r1r!s6	
!		
z
Random.samplecCs||||j�S)zHGet a random number in the range [a, b) or [a, b] depending on rounding.)r)r.rGr]r0r0r1r_szRandom.uniformgg�?cCs�|j�}y(|dkr!dn||||}Wntk
rL|SYnX||krzd|}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�urIr0r0r1r es	(
	


zRandom.triangularcCsf|j}xN|�}d|�}t|d|}||d}|t|�krPqW|||S)z\Normal distribution.

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

        g�?g�?g@)r�
NV_MAGICCONSTrq)r.�mu�sigmar�u1�u2�zZzzr0r0r1r{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.rzr{r0r0r1r�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�?)rqr)r.Zlambdr0r0r1r�szRandom.expovariatecCs|j}|dkr t|�Sd|}|td||�}xc|�}tt|�}|||}|�}	|	d||ks�|	d|t|�krEPqEWd|}
|
|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.rzZkappar�srcr|r~�dr}�q�fZu3Zthetar0r0r1r�s&	
		.
	zRandom.vonmisesvariatecCs|dks|dkr$td��|j}|dkrtd|d�}|t}||}x�|�}d|ko�dkns�qdd|�}t|d|�|}	|t|	�}
|||}|||	|
}|td|dks|t|�krd|
|SqdWn�|dkrZ|�}
x|
dkrJ|�}
q2Wt|
�|Sx�|�}
t|t}||
}|dkr�|d|}
nt|||�}
|�}|dkr�||
|dkr�Pq]|t|
�kr]Pq]W|
|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)rPrr��LOG4rqr�
SG_MAGICCONST�_e)r.�alpha�betarZainvZbbbZcccr|r}�vr/r~rcrxr]�pr0r0r1r�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�rqr��_sin)r.rzr{rr~Zx2piZg2radr0r0r1r!+s			
zRandom.gausscCs>|j|d�}|dkr"dS|||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��yr0r0r1r"`s
zRandom.betavariatecCs d|j�}d|d|S)z3Pareto distribution.  alpha is the shape parameter.g�?)r)r.r�rxr0r0r1r#rszRandom.paretovariatecCs'd|j�}|t|�d|S)zfWeibull distribution.

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

        g�?)rrq)r.r�r�rxr0r0r1r${szRandom.weibullvariate)"�__name__�
__module__�__qualname__�__doc__rKr2rr%r&rSrTrUr9rr�BPFra�_MethodType�_BuiltinMethodTyperVrrrrr rrrrrr!r"r#r$r0r0)rJr1rDs6	),
>0H5	c@sPeZdZdZdd�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).r6r3r,)r9r:r;�	RECIP_BPF)r.r0r0r1r�szSystemRandom.randomcCsl|dkrtd��|t|�kr6td��|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 integerr6�r3)rPr9rQr:r;)r.rbZnumbytesr/r0r0r1r'�szSystemRandom.getrandbitscOsdS)z<Stub method.  Not used for a system random number generator.Nr0)r.�args�kwdsr0r0r1r�szSystemRandom.seedcOstd��dS)zAMethod should not be called for a system random number generator.z*System entropy source does not have state.N)r<)r.r�r�r0r0r1�_notimplemented�szSystemRandom._notimplementedN)
r�r�r�r�rr'rr�r%r&r0r0r0r1r(�s
cCsddl}t|d|j�d}d}d}d
}|j�}xVt|�D]H}	||�}
||
7}||
|
}t|
|�}t|
|�}qPW|j�}tt||d�ddd�||}t||||�}
td	||
||f�dS)Nr�timesgg _�Br,zsec,�end� z"avg %g, stddev %g, min %g, max %g
g _��)r=�printr�ri�min�max�roundr�)r\�funcr�r=ZtotalZsqsumZsmallestZlargestZt0rgr/Zt1ZavgZstddevr0r0r1�_test_generator�s&
 
r�i�cCst|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 )�Nr0r0r1�_test�s r��__main__)Jr��warningsrr_�typesrr�rr�Zmathrrqrrrr�rr�r	rpr
r�rr�rr�r
r��osrr;�_collections_abcrrnrroZhashlibrrE�__all__ryr�r�r�r�r�Z_randomrr(r�r�Z_instrrrr rrrrrrrrrrr!r"r#r$r%r&r'r�r0r0r0r1�<module>%sd("		
��F!																						

Hacked By AnonymousFox1.0, Coded By AnonymousFox