grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026ž õ fZ>e3j?Z?e3j@Z@e3jAZAe3jBZBe3jCZCe3jDZDe3jEZEe3jFZFe3jGZGe3jHZHeId0kr{e2ƒnd(S(1u‰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(uwarn(u MethodTypeuBuiltinMethodType(uloguexpupiueuceil(usqrtuacosucosusin(uurandom(uSetuSequence(usha512uRandomuseedurandomuuniformurandintuchoiceusampleu randrangeushuffleu normalvariateulognormvariateu expovariateuvonmisesvariateu gammavariateu triangularugaussu betavariateu paretovariateuweibullvariateugetstateusetstateu getrandbitsu SystemRandomigà?g@g@gð?g@i5iNcsƒ|EeZdZdZdZd7dd„Zd7d‡fdd†Z‡fdd †Z‡fd d †Z d d „Z dd„Z dd„Z d7de dd„Zdd„Ze de>eeedd„Zdd„Zd7dd„Zdd„Zdd „Zd!d"d7d#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„Zd1d2„Z d3d4„Z!d5d6„Z"‡S(8uRandomuã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. icCs|j|ƒd|_dS(ueInitialize an instance. Optional argument x controls seeding, as for Random.seed(). N(useeduNoneu gauss_next(uselfux((u+/opt/alt/python33/lib64/python3.3/random.pyu__init__Ts uRandom.__init__ic sï|dkrbytjtdƒdƒ}Wqbtk r^ddl}t|jƒdƒ}YqbXn|dkrÒt|ttt fƒrÒt|tƒr¤|j ƒ}n|t |ƒj ƒ7}tj|dƒ}qÒnt ƒj|ƒd|_dS(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. For version 2 (the default), all of the bits are used if *a* is a str, bytes, or bytearray. For version 1, the hash() of *a* is used instead. If *a* is an int, all bits are used. i ubigiNii(uNoneuintu from_bytesu_urandomuNotImplementedErrorutimeu isinstanceustrubytesu bytearrayuencodeu_sha512udigestusuperuseedu gauss_next(uselfuauversionutime(u __class__(u+/opt/alt/python33/lib64/python3.3/random.pyuseed]s    u Random.seedcs|jtƒjƒ|jfS(u9Return internal state; can be passed to setstate() later.(uVERSIONusuperugetstateu gauss_next(uself(u __class__(u+/opt/alt/python33/lib64/python3.3/random.pyugetstate{suRandom.getstatecs×|d}|dkr;|\}}|_tƒj|ƒn˜|dkrº|\}}|_ytdd„|Dƒƒ}Wn.tk r¦}zt|‚WYdd}~XnXtƒj|ƒntd||jfƒ‚dS(u:Restore internal state from object returned by getstate().iiicss|]}|dVqdS(ii Nl((u.0ux((u+/opt/alt/python33/lib64/python3.3/random.pyu Œsu"Random.setstate..Nu?state with version %s passed to Random.setstate() of version %s(u gauss_nextusuperusetstateutupleu ValueErroru TypeErroruVERSION(uselfustateuversionu internalstateue(u __class__(u+/opt/alt/python33/lib64/python3.3/random.pyusetstates   uRandom.setstatecCs |jƒS(N(ugetstate(uself((u+/opt/alt/python33/lib64/python3.3/random.pyu __getstate__šsuRandom.__getstate__cCs|j|ƒdS(N(usetstate(uselfustate((u+/opt/alt/python33/lib64/python3.3/random.pyu __setstate__�suRandom.__setstate__cCs|jf|jƒfS(N(u __class__ugetstate(uself((u+/opt/alt/python33/lib64/python3.3/random.pyu __reduce__ suRandom.__reduce__ic Cs‚||ƒ}||kr'tdƒ‚n|d kr[|dkrL|j|ƒStdƒ‚n||ƒ}||kr‚tdƒ‚n||}|dkrµ|dkrµ||j|ƒS|dkrÝtd|||fƒ‚n||ƒ}||krtdƒ‚n|dkr%||d|} n-|dkrF||d|} n tdƒ‚| dkrmtdƒ‚n|||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. u!non-integer arg 1 for randrange()iuempty range for randrange()u non-integer stop for randrange()iu'empty range for randrange() (%d,%d, %d)u non-integer step for randrange()uzero step for randrange()N(u ValueErroruNoneu _randbelow( uselfustartustopustepu_intuistartuistopuwidthuistepun((u+/opt/alt/python33/lib64/python3.3/random.pyu randrange¥s4               uRandom.randrangecCs|j||dƒS(uJReturn random integer in range [a, b], including both end points. i(u randrange(uselfuaub((u+/opt/alt/python33/lib64/python3.3/random.pyurandintÑsuRandom.randintc Csê|j}||jƒ|ks0||ƒ|krk|jƒ}||ƒ} x| |krf||ƒ} qKW| S|j} ||kr›tdƒ|| ƒ|ƒS||} || |} | ƒ} x| | kr×| ƒ} q¿W|| |ƒ|S(uCReturn a random int in the range [0,n). Raises ValueError if n==0.u¤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.(u getrandbitsurandomu bit_lengthu_warn( uselfunuintumaxsizeutypeuMethodu BuiltinMethodu getrandbitsukururandomuremulimit((u+/opt/alt/python33/lib64/python3.3/random.pyu _randbelow×s" '        uRandom._randbelowc CsBy|jt|ƒƒ}Wntk r9tdƒ‚YnX||S(u2Choose a random element from a non-empty sequence.u$Cannot choose from an empty sequence(u _randbelowulenu ValueErroru IndexError(uselfusequi((u+/opt/alt/python33/lib64/python3.3/random.pyuchoiceõs  u Random.choicecCsÏ|dkrk|j}x³ttdt|ƒƒƒD]3}||dƒ}||||||<|| 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. iN(uNoneu _randbelowureversedurangeulenuint(uselfuxurandomu randbelowuiuju_int((u+/opt/alt/python33/lib64/python3.3/random.pyushuffleýs  "$"uRandom.shufflec Cs•t|tƒrt|ƒ}nt|tƒs<tdƒ‚n|j}t|ƒ}d|koh|kns|tdƒ‚nd g|}d}|dkr¿|dt t |ddƒƒ7}n||kr%t |ƒ}x·t |ƒD]:}|||ƒ} || ||<|||d|| Population must be a sequence or set. For dicts, use list(d).iuSample larger than populationiiiiiN(u isinstanceu_Setutupleu _Sequenceu TypeErroru _randbelowulenu ValueErroruNoneu_ceilu_logulisturangeusetuadd( uselfu populationuku randbelowunuresultusetsizeupooluiujuselectedu selected_add((u+/opt/alt/python33/lib64/python3.3/random.pyusamples6    $      u Random.samplecCs||||jƒS(uHGet a random number in the range [a, b) or [a, b] depending on rounding.(urandom(uselfuaub((u+/opt/alt/python33/lib64/python3.3/random.pyuuniformPsuRandom.uniformggð?cCsx|jƒ}|dkrdn||||}||kr`d|}d|}||}}n|||||dS(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(urandomuNone(uselfulowuhighumodeuuuc((u+/opt/alt/python33/lib64/python3.3/random.pyu triangularVs $   uRandom.triangularcCsh|j}xP|ƒ}d|ƒ}t|d|}||d}|t|ƒ kr Pq q |||S(u\Normal distribution. mu is the mean, and sigma is the standard deviation. gð?gà?g@(urandomu NV_MAGICCONSTu_log(uselfumuusigmaurandomuu1uu2uzuzz((u+/opt/alt/python33/lib64/python3.3/random.pyu normalvariateis   uRandom.normalvariatecCst|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(uselfumuusigma((u+/opt/alt/python33/lib64/python3.3/random.pyulognormvariate‚suRandom.lognormvariatecCstd|jƒƒ |S(u^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ð?(u_logurandom(uselfulambd((u+/opt/alt/python33/lib64/python3.3/random.pyu expovariateŽsuRandom.expovariatecCs|j}|dkr t|ƒSd|}|td||ƒ}xe|ƒ}tt|ƒ}|||}|ƒ} | d||ks£| d|t|ƒkrEPqEqEd|} | |d| |} |ƒ} | dkrö|t| ƒt} n|t| ƒt} | S(uFCircular 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ð?(urandomuTWOPIu_sqrtu_cosu_piu_expu_acos(uselfumuukappaurandomusuruu1uzuduu2uqufuu3utheta((u+/opt/alt/python33/lib64/python3.3/random.pyuvonmisesvariate¡s&      .   uRandom.vonmisesvariatecCs |dks|dkr'tdƒ‚n|j}|dkrtd|dƒ}|t}||}x |ƒ}d|ko‡dkns’qgnd|ƒ}t|d|ƒ|} |t| ƒ} |||} ||| | } | td| dks| t| ƒkrg| |Sqgnè|dkr_|ƒ} x| dkrO|ƒ} q7Wt| ƒ |Sx�|ƒ} t|t}|| }|dkr |d|} nt|||ƒ } |ƒ}|dkrå|| |dkrüPqüqb|t| ƒkrbPqbqb| |SdS( uZGamma 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 gu*gammavariate: alpha and beta must be > 0.0gð?g@gH¯¼šò×z>gËPÊÿÿï?g@N(u ValueErrorurandomu_sqrtuLOG4u_logu_expu SG_MAGICCONSTu_e(uselfualphaubetaurandomuainvubbbucccuu1uu2uvuxuzuruuubup((u+/opt/alt/python33/lib64/python3.3/random.pyu gammavariateÑsJ      *        uRandom.gammavariatecCsƒ|j}|j}d|_|dkrw|ƒt}tdtd|ƒƒƒ}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ð?NgÀ(urandomu gauss_nextuNoneuTWOPIu_sqrtu_logu_cosu_sin(uselfumuusigmaurandomuzux2piug2rad((u+/opt/alt/python33/lib64/python3.3/random.pyugausss     u Random.gausscCs>|j|dƒ}|dkr"dS|||j|dƒSdS(u�Beta distribution. Conditions on the parameters are alpha > 0 and beta > 0. Returned values range between 0 and 1. gð?igN(u gammavariate(uselfualphaubetauy((u+/opt/alt/python33/lib64/python3.3/random.pyu betavariateNs  uRandom.betavariatecCs d|jƒ}d|d|S(u3Pareto distribution. alpha is the shape parameter.gð?(urandom(uselfualphauu((u+/opt/alt/python33/lib64/python3.3/random.pyu paretovariate`suRandom.paretovariatecCs'd|jƒ}|t|ƒ d|S(ufWeibull distribution. alpha is the scale parameter and beta is the shape parameter. gð?(urandomu_log(uselfualphaubetauu((u+/opt/alt/python33/lib64/python3.3/random.pyuweibullvariateisuRandom.weibullvariateN(#u__name__u __module__u __qualname__u__doc__uVERSIONuNoneu__init__useedugetstateusetstateu __getstate__u __setstate__u __reduce__uintu randrangeurandintuBPFutypeu _MethodTypeu_BuiltinMethodTypeu _randbelowuchoiceushuffleusampleuuniformu triangularu normalvariateulognormvariateu expovariateuvonmisesvariateu gammavariateugaussu betavariateu paretovariateuweibullvariate(u __locals__((u __class__u+/opt/alt/python33/lib64/python3.3/random.pyuRandomDs6     ,    >    0 H 5  cBsT|EeZdZdZdd„Zdd„Zdd„Zdd „ZeZZ d S( u SystemRandomuÝ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(u3Get the next random number in the range [0.0, 1.0).iubigi(uintu from_bytesu_urandomu RECIP_BPF(uself((u+/opt/alt/python33/lib64/python3.3/random.pyurandom~suSystemRandom.randomcCsr|dkrtdƒ‚n|t|ƒkr<tdƒ‚n|dd}tjt|ƒdƒ}||d|?S(u:getrandbits(k) -> x. Generates an int with k random bits.iu(number of bits must be greater than zerou#number of bits should be an integeriiubig(u ValueErroruintu TypeErroru from_bytesu_urandom(uselfukunumbytesux((u+/opt/alt/python33/lib64/python3.3/random.pyu getrandbits‚s uSystemRandom.getrandbitscOsdS(u<Stub method. Not used for a system random number generator.N(uNone(uselfuargsukwds((u+/opt/alt/python33/lib64/python3.3/random.pyuseedŒsuSystemRandom.seedcOstdƒ‚dS(uAMethod should not be called for a system random number generator.u*System entropy source does not have state.N(uNotImplementedError(uselfuargsukwds((u+/opt/alt/python33/lib64/python3.3/random.pyu_notimplemented�suSystemRandom._notimplementedN( u__name__u __module__u __qualname__u__doc__urandomu getrandbitsuseedu_notimplementedugetstateusetstate(u __locals__((u+/opt/alt/python33/lib64/python3.3/random.pyu SystemRandomvs    cCsddl}t|d|jƒd}d}d}d }|jƒ}xVt|ƒD]H} ||Œ} || 7}|| | }t| |ƒ}t| |ƒ}qPW|jƒ} tt| |dƒdddƒ||} t||| | ƒ} td | | ||fƒdS( Niutimesgg _ Biusec,uendu u!avg %g, stddev %g, min %g, max %gg _ Â(utimeuprintu__name__urangeuminumaxuroundu_sqrt(unufuncuargsutimeutotalusqsumusmallestulargestut0uiuxut1uavgustddev((u+/opt/alt/python33/lib64/python3.3/random.pyu_test_generator—s&       u_test_generatoriÐ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(Nggð?g{®Gáz„?gš™™™™™¹?g@gà?gÍÌÌÌÌÌì?g4@gi@g@(ggð?(ggð?(ggð?(g{®Gáz„?gð?(gš™™™™™¹?gð?(gš™™™™™¹?g@(gà?gð?(gÍÌÌÌÌÌì?gð?(gð?gð?(g@gð?(g4@gð?(gi@gð?(ggð?(g@g@gUUUUUUÕ?(ggð?gUUUUUUÕ?( u_test_generatorurandomu normalvariateulognormvariateuvonmisesvariateu gammavariateugaussu betavariateu triangular(uN((u+/opt/alt/python33/lib64/python3.3/random.pyu_test­s u_testu__main__(Ju__doc__uwarningsuwarnu_warnutypesu MethodTypeu _MethodTypeuBuiltinMethodTypeu_BuiltinMethodTypeumathulogu_loguexpu_expupiu_piueu_euceilu_ceilusqrtu_sqrtuacosu_acosucosu_cosusinu_sinuosuurandomu_urandomucollections.abcuSetu_SetuSequenceu _Sequenceuhashlibusha512u_sha512u__all__u NV_MAGICCONSTuTWOPIuLOG4u SG_MAGICCONSTuBPFu RECIP_BPFu_randomuRandomu SystemRandomu_test_generatoru_testu_instuseedurandomuuniformu triangularurandintuchoiceu randrangeusampleushuffleu normalvariateulognormvariateu expovariateuvonmisesvariateu gammavariateugaussu betavariateu paretovariateuweibullvariateugetstateusetstateu getrandbitsu__name__(((u+/opt/alt/python33/lib64/python3.3/random.pyu%sd("         ÿÿ4!