;
Êâ"Ic               @   sn  d  Z  d d l m Z d d l m Z d d l m Z m	 Z
 d d l m Z m Z m Z m Z m Z d d l m Z m Z m Z m Z d d l m Z  d d l! m" Z# d	 d
 d d d d d d d d d d d d d d d d d d d d d g Z$ d  e d! ƒ e d" ƒ Z% d" e Z& e d# ƒ Z' d$ e d% ƒ Z( d& Z) d' e) Z* d d( l+ Z+ Gd) „  d	 e+ j, ƒ Z, Gd* „  d e, ƒ Z- d+ „  Z. d, d- „ Z/ e, ƒ  Z0 e0 j1 Z1 e0 j2 Z2 e0 j3 Z3 e0 j4 Z4 e0 j5 Z5 e0 j6 Z6 e0 j7 Z7 e0 j8 Z8 e0 j9 Z9 e0 j: Z: e0 j; Z; e0 j< Z< e0 j= Z= e0 j> Z> e0 j? Z? e0 j@ Z@ e0 jA ZA e0 jB ZB e0 jC ZC e0 jD ZD e0 jE ZE eF d. k o e/ ƒ  n d( S(/   u‰  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.

i    (   u   division(   u   warn(   u
   MethodTypeu   BuiltinMethodType(   u   logu   expu   piu   eu   ceil(   u   sqrtu   acosu   cosu   sin(   u   urandom(   u   hexlifyu   Randomu   seedu   randomu   uniformu   randintu   choiceu   sampleu	   randrangeu   shuffleu   normalvariateu   lognormvariateu   expovariateu   vonmisesvariateu   gammavariateu
   triangularu   gaussu   betavariateu   paretovariateu   weibullvariateu   getstateu   setstateu   getrandbitsu   SystemRandomi   g      à¿g       @g      @g      ð?g      @i5   i   Nc                s?  |  Ee  Z d  Z d Z d d „ Z d ‡  f d † Z ‡  f d †  Z ‡  f d †  Z d „  Z	 d „  Z
 d „  Z d d	 e d d	 e >d
 „ Z d „  Z e e d	 e >e e d „ Z d „  Z d e d „ Z d „  Z d „  Z d d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! ‡  S(   uã  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.

    i   c             C   s   |  j  | ƒ d |  _ d S(   ue   Initialize an instance.

        Optional argument x controls seeding, as for Random.seed().
        N(   u   seedu   Noneu
   gauss_next(   u   selfu   x(    (    u#   /mit/python/lib/python3.0/random.pyu   __init__T   s    c          
      s†   | d k o\ y t t t d ƒ ƒ d ƒ } Wqi t k
 o* d d l } t | j ƒ  d ƒ } Yqi Xn t ƒ  j | ƒ d |  _ d S(   u   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 not None or an int or long, hash(a) is used instead.
        i   i    Ni   (	   u   Noneu   intu   _hexlifyu   _urandomu   NotImplementedErroru   timeu   superu   seedu
   gauss_next(   u   selfu   au   time(   u	   __class__(    u#   /mit/python/lib/python3.0/random.pyu   seed]   s    	 c                s   |  j  t ƒ  j ƒ  |  j f S(   u9   Return internal state; can be passed to setstate() later.(   u   VERSIONu   superu   getstateu
   gauss_next(   u   self(   u	   __class__(    u#   /mit/python/lib/python3.0/random.pyu   getstatep   s    c                sà   | d } | d k o& | \ } } |  _  t ƒ  j | ƒ n  | d k oy | \ } } |  _  y t d „  | Dƒ ƒ } Wn0 t k
 o$ } z t | ‚ WYd d } ~ Xn Xt t |  ƒ j | ƒ n t d | |  j f ƒ ‚ d S(   u:   Restore internal state from object returned by getstate().i    i   i   c             s   s   |  ] } | d Vq d S(   i   i    Nl        (    (   u   .0u   x(    (    u#   /mit/python/lib/python3.0/random.pyu	   <genexpr>   s    Nu?   state with version %s passed to Random.setstate() of version %s(   u
   gauss_nextu   superu   setstateu   tupleu
   ValueErroru	   TypeErroru   Randomu   VERSION(   u   selfu   stateu   versionu   internalstateu   e(   u	   __class__(    u#   /mit/python/lib/python3.0/random.pyu   setstatet   s    
c             C   s
   |  j  ƒ  S(   N(   u   getstate(   u   self(    (    u#   /mit/python/lib/python3.0/random.pyu   __getstate__   s    c             C   s   |  j  | ƒ d  S(   N(   u   setstate(   u   selfu   state(    (    u#   /mit/python/lib/python3.0/random.pyu   __setstate__’   s    c             C   s   |  j  d |  j ƒ  f S(   N(    (   u	   __class__u   getstate(   u   self(    (    u#   /mit/python/lib/python3.0/random.pyu
   __reduce__•   s    i   c             C   s  | | ƒ } | | k o t  d ƒ ‚ n | | k oM | d k o0 | | k o |  j | ƒ S| |  j ƒ  | ƒ St  d ƒ ‚ n | | ƒ } | | k o t  d ƒ ‚ n | | }	 | d k oQ |	 d k oD |	 | k o | | |  j |	 ƒ ƒ S| | | |  j ƒ  |	 ƒ ƒ S| d k o t  d | | |	 f ƒ ‚ n | | ƒ }
 |
 | k o t  d ƒ ‚ n |
 d k o |	 |
 d |
 } n0 |
 d k  o |	 |
 d |
 } n t  d ƒ ‚ | d k o t  d ƒ ‚ n | | k o | |
 |  j | ƒ S| |
 | |  j ƒ  | ƒ S(	   u  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.
        Do not supply the 'int', 'default', and 'maxwidth' arguments.
        u!   non-integer arg 1 for randrange()i    u   empty range for randrange()u    non-integer stop for randrange()i   u'   empty range for randrange() (%d,%d, %d)u    non-integer step for randrange()u   zero step for randrange()(   u
   ValueErroru
   _randbelowu   random(   u   selfu   startu   stopu   stepu   intu   defaultu   maxwidthu   istartu   istopu   widthu   istepu   n(    (    u#   /mit/python/lib/python3.0/random.pyu	   randrangeš   s@    
c             C   s   |  j  | | d ƒ S(   uJ   Return random integer in range [a, b], including both end points.
        i   (   u	   randrange(   u   selfu   au   b(    (    u#   /mit/python/lib/python3.0/random.pyu   randintÚ   s    c       
      C   sË   y |  j  } Wn t k
 o Ynz Xt |  j ƒ | k p t | ƒ | k oO | d | | d d ƒ ƒ } | | ƒ }	 x |	 | k o | | ƒ }	 qy W|	 S| | k o t d ƒ n | |  j ƒ  | ƒ S(   u£   Return a random int in the range [0,n)

        Handles the case where n has more bits than returned
        by a single call to the underlying generator.
        grÄZ|
 ð?i   g       @ug   Underlying random() generator does not supply 
enough bits to choose from a population range this large(   u   getrandbitsu   AttributeErroru   typeu   randomu   _warn(
   u   selfu   nu   _logu   intu	   _maxwidthu   _Methodu   _BuiltinMethodu   getrandbitsu   ku   r(    (    u#   /mit/python/lib/python3.0/random.pyu
   _randbelowà   s    ) c             C   s   | t  |  j ƒ  t | ƒ ƒ S(   u2   Choose a random element from a non-empty sequence.(   u   intu   randomu   len(   u   selfu   seq(    (    u#   /mit/python/lib/python3.0/random.pyu   choiceý   s    c             C   sx   | d k o |  j } n xW t t d t | ƒ ƒ ƒ D]: } | | ƒ  | d ƒ } | | | | | | <| | <q6 Wd S(   u×   x, random=random.random -> shuffle list x in place; return None.

        Optional arg random is a 0-argument function returning a random
        float in [0.0, 1.0); by default, the standard random.random.
        i   N(   u   Noneu   randomu   reversedu   rangeu   len(   u   selfu   xu   randomu   intu   iu   j(    (    u#   /mit/python/lib/python3.0/random.pyu   shuffle  s     c             C   sÔ  t  | t t f ƒ o t | ƒ } n t | d ƒ p t | d ƒ o t d ƒ ‚ n |  j } t | ƒ } d | k o
 | k n p t d ƒ ‚ n t	 } d g | } d } | d k o% | d t t | d	 d ƒ ƒ 7} n | | k ob t | ƒ } xÏ t | ƒ D]A }	 | | ƒ  | |	 ƒ }
 | |
 | |	 <| | |	 d
 | |
 <qWn} t ƒ  } | j } xg t | ƒ D]Y }	 | | ƒ  | ƒ }
 x% |
 | k o | | ƒ  | ƒ }
 qW| |
 ƒ | |
 | |	 <qsW| S(   u=  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)
        u   __getitem__u   keysuB   Population must be a sequence or set.  For dicts, use dict.keys().i    u   Sample larger than populationi   i   i   i   i   N(   u
   isinstanceu   setu	   frozensetu   tupleu   hasattru	   TypeErroru   randomu   lenu
   ValueErroru   intu   Noneu   _ceilu   _logu   listu   rangeu   add(   u   selfu
   populationu   ku   randomu   nu   _intu   resultu   setsizeu   poolu   iu   ju   selectedu   selected_add(    (    u#   /mit/python/lib/python3.0/random.pyu   sample  s>    !	% 		  
c             C   s   | | | |  j  ƒ  S(   u(   Get a random number in the range [a, b).(   u   random(   u   selfu   au   b(    (    u#   /mit/python/lib/python3.0/random.pyu   uniformN  s    g        g      ð?c             C   s|   |  j  ƒ  } | d k o d n | | | | } | | k o% d | } d | } | | } } n | | | | | d S(   uÜ   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

        g      à?g      ð?N(   u   randomu   None(   u   selfu   lowu   highu   modeu   uu   c(    (    u#   /mit/python/lib/python3.0/random.pyu
   triangularT  s    	&

c             C   sj   |  j  } xR | ƒ  } d | ƒ  } t | d | } | | d } | t | ƒ k o Pq q | | | S(   u\   Normal distribution.

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

        g      ð?g      à?g      @(   u   randomu   NV_MAGICCONSTu   _log(   u   selfu   muu   sigmau   randomu   u1u   u2u   zu   zz(    (    u#   /mit/python/lib/python3.0/random.pyu   normalvariateg  s    		c             C   s   t  |  j | | ƒ ƒ S(   uû   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.

        (   u   _expu   normalvariate(   u   selfu   muu   sigma(    (    u#   /mit/python/lib/python3.0/random.pyu   lognormvariate€  s    c             C   s?   |  j  } | ƒ  } x | d k o | ƒ  } q Wt | ƒ | S(   uì   Exponential distribution.

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

        gH¯¼šò×z>(   u   randomu   _log(   u   selfu   lambdu   randomu   u(    (    u#   /mit/python/lib/python3.0/random.pyu   expovariateŒ  s    		 c             C   s7  |  j  } | d k o t | ƒ  Sd t d d | | ƒ } | t d | ƒ d | } d | | d | } x~ | ƒ  } t t | ƒ } d | | | | }	 | | |	 }
 | ƒ  } | |
 d |
 k  p | |
 t d |
 ƒ k o Pqs qs | ƒ  } | d k o | t t |	 ƒ } n | t t |	 ƒ } | S(   uF  Circular 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      @g       @g      à?(   u   randomu   TWOPIu   _sqrtu   _cosu   _piu   _expu   _acos(   u   selfu   muu   kappau   randomu   au   bu   ru   u1u   zu   fu   cu   u2u   u3u   theta(    (    u#   /mit/python/lib/python3.0/random.pyu   vonmisesvariateŸ  s&    			0	c             C   s"  | d k p | d k o t  d ƒ ‚ n |  j } | d k oê t d | d ƒ } | t } | | } x³| ƒ  } d | k  o
 d k  n p qk n d | ƒ  } t | d | ƒ | }	 | t |	 ƒ }
 | | | } | | |	 |
 } | t d | d k p | t | ƒ k o	 |
 | Sqk nõ | d k o7 | ƒ  } x | d k o | ƒ  } qCWt | ƒ | Sx¥ | ƒ  } t | t } | | } | d k o | d | }
 n t | | | ƒ }
 | ƒ  } | d k o | |
 | d k o Pqqq| t |
 ƒ k o Pqqqq|
 | Sd S(	   ux   Gamma distribution.  Not the gamma function!

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

        g        u*   gammavariate: alpha and beta must be > 0.0g      ð?g       @gH¯¼šò×z>gËPÊÿÿï?g      @N(   u
   ValueErroru   randomu   _sqrtu   LOG4u   _logu   _expu   SG_MAGICCONSTu   _e(   u   selfu   alphau   betau   randomu   ainvu   bbbu   cccu   u1u   u2u   vu   xu   zu   ru   uu   bu   p(    (    u#   /mit/python/lib/python3.0/random.pyu   gammavariateÑ  sL    	

	,	 	
		c             C   s…   |  j  } |  j } d |  _ | d k oQ | ƒ  t } t d t d | ƒ  ƒ ƒ } t | ƒ | } t | ƒ | |  _ n | | | S(   uØ   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.

        g       Àg      ð?N(   u   randomu
   gauss_nextu   Noneu   TWOPIu   _sqrtu   _logu   _cosu   _sin(   u   selfu   muu   sigmau   randomu   zu   x2piu   g2rad(    (    u#   /mit/python/lib/python3.0/random.pyu   gauss  s    			c             C   s@   |  j  | d ƒ } | d k o d S| | |  j  | d ƒ Sd S(   u   Beta distribution.

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

        g      ð?i    g        N(   u   gammavariate(   u   selfu   alphau   betau   y(    (    u#   /mit/python/lib/python3.0/random.pyu   betavariateH  s    
c             C   s%   d |  j  ƒ  } d t | d | ƒ S(   u3   Pareto distribution.  alpha is the shape parameter.g      ð?(   u   randomu   pow(   u   selfu   alphau   u(    (    u#   /mit/python/lib/python3.0/random.pyu   paretovariateZ  s    c             C   s,   d |  j  ƒ  } | t t | ƒ d | ƒ S(   uf   Weibull distribution.

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

        g      ð?(   u   randomu   powu   _log(   u   selfu   alphau   betau   u(    (    u#   /mit/python/lib/python3.0/random.pyu   weibullvariatec  s    N("   u   __name__u
   __module__u   __doc__u   VERSIONu   Noneu   __init__u   seedu   getstateu   setstateu   __getstate__u   __setstate__u
   __reduce__u   intu   BPFu	   randrangeu   randintu   _logu   _MethodTypeu   _BuiltinMethodTypeu
   _randbelowu   choiceu   shuffleu   sampleu   uniformu
   triangularu   normalvariateu   lognormvariateu   expovariateu   vonmisesvariateu   gammavariateu   gaussu   betavariateu   paretovariateu   weibullvariate(   u
   __locals__(    (   u	   __class__u#   /mit/python/lib/python3.0/random.pyu   RandomD   s8   
				?			?					2	B	5			c             B   sB   |  Ee  Z d  Z d „  Z d „  Z d „  Z d „  Z e Z Z d S(   uÝ   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).
    c             C   s!   t  t t d ƒ ƒ d ƒ d ?t S(   u3   Get the next random number in the range [0.0, 1.0).i   i   i   (   u   intu   _hexlifyu   _urandomu	   RECIP_BPF(   u   self(    (    u#   /mit/python/lib/python3.0/random.pyu   randomx  s    c             C   sy   | d k o t  d ƒ ‚ n | t | ƒ k o t d ƒ ‚ n | d d } t t t | ƒ ƒ d ƒ } | | d | ?S(   u>   getrandbits(k) -> x.  Generates a long int with k random bits.i    u(   number of bits must be greater than zerou#   number of bits should be an integeri   i   i   (   u
   ValueErroru   intu	   TypeErroru   _hexlifyu   _urandom(   u   selfu   ku   bytesu   x(    (    u#   /mit/python/lib/python3.0/random.pyu   getrandbits|  s    c             O   s   d S(   u<   Stub method.  Not used for a system random number generator.N(   u   None(   u   selfu   argsu   kwds(    (    u#   /mit/python/lib/python3.0/random.pyu   seed†  s    c             O   s   t  d ƒ ‚ d S(   uA   Method should not be called for a system random number generator.u*   System entropy source does not have state.N(   u   NotImplementedError(   u   selfu   argsu   kwds(    (    u#   /mit/python/lib/python3.0/random.pyu   _notimplementedŠ  s    N(	   u   __name__u
   __module__u   __doc__u   randomu   getrandbitsu   seedu   _notimplementedu   getstateu   setstate(   u
   __locals__(    (    u#   /mit/python/lib/python3.0/random.pyu   SystemRandomp  s   
		
		c          	   C   s  d d  l  } t |  d | j ƒ d } d } d } d } | j  ƒ  } xV t |  ƒ D]H }	 | | Œ  }
 | |
 7} | |
 |
 } t |
 | ƒ } t |
 | ƒ } qP W| j  ƒ  } t t | | d ƒ d d d	 ƒ| |  } t | |  | | ƒ } t d
 | | | | f ƒ d  S(   Ni    u   timesg        g    _ Bg    _ Âi   u   sec,u   endu    u!   avg %g, stddev %g, min %g, max %g(   u   timeu   printu   __name__u   rangeu   minu   maxu   roundu   _sqrt(   u   nu   funcu   argsu   timeu   totalu   sqsumu   smallestu   largestu   t0u   iu   xu   t1u   avgu   stddev(    (    u#   /mit/python/lib/python3.0/random.pyu   _test_generator‘  s(     
 
iÐ  c             C   s  t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d ƒ t  |  t d d d f ƒ d  S(   Ng        g      ð?g{®Gáz„?gš™™™™™¹?g       @g      à?gÍÌÌÌÌÌì?g      4@g      i@g      @(    (   g        g      ð?(   g        g      ð?(   g        g      ð?(   g{®Gáz„?g      ð?(   gš™™™™™¹?g      ð?(   gš™™™™™¹?g       @(   g      à?g      ð?(   gÍÌÌÌÌÌì?g      ð?(   g      ð?g      ð?(   g       @g      ð?(   g      4@g      ð?(   g      i@g      ð?(   g        g      ð?(   g      @g      @gUUUUUUÕ?(	   u   _test_generatoru   randomu   normalvariateu   lognormvariateu   vonmisesvariateu   gammavariateu   gaussu   betavariateu
   triangular(   u   N(    (    u#   /mit/python/lib/python3.0/random.pyu   _test§  s     u   __main__(G   u   __doc__u
   __future__u   divisionu   warningsu   warnu   _warnu   typesu
   MethodTypeu   _MethodTypeu   BuiltinMethodTypeu   _BuiltinMethodTypeu   mathu   logu   _logu   expu   _expu   piu   _piu   eu   _eu   ceilu   _ceilu   sqrtu   _sqrtu   acosu   _acosu   cosu   _cosu   sinu   _sinu   osu   urandomu   _urandomu   binasciiu   hexlifyu   _hexlifyu   __all__u   NV_MAGICCONSTu   TWOPIu   LOG4u   SG_MAGICCONSTu   BPFu	   RECIP_BPFu   _randomu   Randomu   SystemRandomu   _test_generatoru   _testu   _instu   seedu   randomu   uniformu
   triangularu   randintu   choiceu	   randrangeu   sampleu   shuffleu   normalvariateu   lognormvariateu   expovariateu   vonmisesvariateu   gammavariateu   gaussu   betavariateu   paretovariateu   weibullvariateu   getstateu   setstateu   getrandbitsu   __name__(    (    (    u#   /mit/python/lib/python3.0/random.pyu   <module>%   sd   ("		
ÿ ÿ .!																							