grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|jÅ�ã@sdZddlmZddlmZmZm Z m Z m ZddlmZmZmZmZddlmZmZmZddlmZddl m!Z"m#Z$ddl%m&Z'dd l(m)Z*m+Z,dd l-m-Z.dd lZ/dd l0Z0zdd l1m2Z1Wne3ymdd l4m2Z1Ynwgd ¢Z5dedƒedƒZ6edƒZ7dedƒZ8dZ9de9 Z:dZ;Gdd„de0j<ƒZe>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ƒd Sd S)$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‡fd d „Zd d„Z dd„Z dd„Z dd„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 dd?„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 |_d S) 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"  û  z Random.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|\}}|_z tdd„|Dƒƒ}Wnty:}zt|‚d}~wwtƒ |¡dStd||jfƒ‚)z:Restore internal state from object returned by getstate().rr8r6css�|]}|dVqdS)lNr<)Ú.0r;r<r<r=Ú »s€z"Random.setstate..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|d kr­|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=Ú ßsz!Random.sample..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..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|dur dn||||}Wn ty|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.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°r r±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=Ús| /    þ  K,    ÿ