Wc-csv ddlmZddlmZmZmZ m Z m Z ddlmZmZmZmZddlmZmZmZddlmZmZm Z!ddl"m#Z$ddl%m&Z'ddl(m)Z*dd l+m,Z-m.Z/dd l0m0Z1dd l"Z2dd l3Z3 dd l4m5Z4gd Z8dedzedz Z9edZ:dedzZ;dZGdde3j~Z?Gdde?Z@e?ZAeAjZBeAjZCeAjZDeAjZEeAjZFeAjZGeAjZHeAjZIeAjZJeAjZKeAjZLeAjZMeAjZNeAjZOeAjZPeAjZQeAjZReAjZSeAjZTeAjZUeAjZVeAjZWeAjZXeAjZYdZZd!dZ[e\e2dre2jeAje^d kr e[d Sd S#e6$r dd l7m5Z4YwxYw)")warn)logexppieceil)sqrtacoscossin)taufloorisfinite)lgammafabslog2)urandom)Sequence)index) accumulaterepeat)bisectN)sha512)Random SystemRandom betavariatebinomialvariatechoicechoices expovariate gammavariategauss getrandbitsgetstatelognormvariate normalvariate paretovariate randbytesrandintrandom randrangesampleseedsetstateshuffle triangularuniformvonmisesvariateweibullvariateg@@?@i5cseZdZ dZd'dZd(fd ZfdZfdZdZd Z d Z d Z d Z d e zfdZe ZdZdefdZdZdZdZdddZd'dd ddZdZd)dZd*dZd*dZdZdZd Zd!Zd"Z d+d$Z!d%Z"d&Z#xZ$S),rNcs: |j|d|_dSN)r+ gauss_next)selfx /usr/lib64/python3.12/random.py__init__zRandom.__init__zs! ! r7c s |dkrt|ttfr~t|tr|jdn|}|rt |ddznd}t t|D] }d|z|z dz}|t |z}|dkrdn|}n|d kryt|tttfrYt|tr|j}tj|t|jz}nEt|tdtttttfs td t!j#|d|_dS) Nr8zlatin-1riCBlir7zOThe only supported seed types are: None, int, float, str, bytes, and bytearray.) isinstanceZstrZbytesZdecodeZordZmaplenZ bytearrayZencodeint from_bytes_sha512ZdigestZtypeZfloat TypeErrorsuperr+r;)r<aversionr=c __class__ r?r+z Random.seedsK " a<r?z z"Random.setstate..s"%K%Ka7mmmmm%K%KrAzstate with version z( passed to Random.setstate() of version )r;rJr,Ztuple ValueErrorrIrP)r<staterLZ internalstaterrNrOr?r,zRandom.setstatesH( a<<6; 3G]DO G  ] + + + + \\6; 3G]DO  ' %%K%K]%K%K K  G  ] + + + +*%ggt|||56 6  ' ' 'Q& 's B B3&B..B3cs$|jSr:)r"r< r? __getstate__zRandom.__getstate__s}}rAcs*|j|dSr:)r,)r<rTr>r? __setstate__zRandom.__setstate__s erAcs>|jd|jfS)NrQ)rNr"rUrVr? __reduce__zRandom.__reduce__s~~r4==?22rAc s |jD]W}d|jvrdSd|jvr|j|_dSd|jvsE|j|_dSdS)N _randbelowr!r()Z__mro__Z__dict___randbelow_with_getrandbitsrZ_randbelow_without_getrandbits)ZclsZkwargsrM r?__init_subclass__zRandom.__init_subclass__s   Aqzz)) **!$!@!@1::%%!$!C!C  rAcs |j}|j}||}||kr||}||kr|Sr:)r!Z bit_length)r<nr!kr r?r[z"Random._randbelow_with_getrandbitssKE&& LLN KN1ff AA1ffrAr8cs |j}||kr#tdt||zS||z}||z |z }|}||kr|}||krt||z|zS)NzUnderlying 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(_warn_floor)r<r_Zmaxsizer(ZremZlimitra r?r\z%Random._randbelow_without_getrandbitss  << N O O&&(Q,' 'k3') FH5jjA5jja'k"Q&&rAcsP |j|dzj|dS)NZlittle)r!Zto_bytesr<r_r>r?r&zRandom.randbytess'&A&//8<r?rz Random.choiceQs.@sCD D4??3s8,--rAcs |j}ttdt|D]%}||dz}||||c||<||<'dSrj)rZZreversedrangerE)r<r= randbelowijrbr?r-zRandom.shuffleWsd7OO %3q6*+ $ $A !a% A1qtJAaD!A$$ $ $rA)countscs tts tdt}|t t |t|kr t dj}t|ts td|dkr t d|jt||}tfd|DS|j}d|cxkr|kst dt ddg|z}d } |d kr"| d tt|d zd zz } || krHt } t|D]*} ||| z } | | || <| || z d z | | <,|St} | j }t|D]1} ||} | | vr||} | | vr|| | || <3|S)NzAPopulation must be a sequence. For dicts or sets, use sorted(d).z2The number of counts does not match the populationzCounts must be integersrz)Total of counts must be greater than zero)r`cs2g|]}|SrQrQ)rRsr cum_counts populations r? z!Random.sample..s'JJJ!Jvvj!4555JrAz,Sample larger than population or is negativeiir2r9r8)rD _SequencerIrElist _accumulaterSZpoprFr*rm_bisectrZ_ceil_logZsetZadd)r<rtr`rqr_totalZ selectionsrnZresultZsetsizeZpoolrorpZselectedZ selected_addrrss ` @@r?r*z Random.sample`s h*i00@A A  O  k&12J:!## !UVVNN$EeS)) 9::zz !LMMU5\Q7JFJJJJJJzJJ JOO A{{{{{{KL LKL L! q55 qE$q1ua.11 1G << #D1X * *Ia!e$ Gq q1uqy/Q uH#<.s-RRRA 55A#6777RrAz4The number of choices must be a keyword argument: k=z2Cannot specify both weights and cumulative weightsz3The number of weights does not match the populationrCz*Total of weights must be greater than zerozTotal of weights must be finiter8c sHg|]}zdS)rrQ)rRrorr}hirtr(r|s r?rurs@+++66+vvx%/?BGHHH+rA) r(rErd_repeatrwrxrIrDrFrS _isfinitery) r<rtZweightsr}r`rr rr_r(r|s ` ` @@@@@@r?rzRandom.choicess   O  SRRRRRRRqAQRRR ";w#78  PQ Q { q RS SB#% C<<IJ J>? ? U+++++++++ q)++ +%   !'3//MMM  s C662D(cs8 |||z |jzzSr:r(rkr]r?r/zRandom.uniformsRAET[[]***rAr~r5cs |j} |dn ||z ||z z }||krd|z }d|z }||}}|||z t||zzzS#t$r|cYSwxYw)N?r5)r(ZZeroDivisionError_sqrt)r<lowhighZmodeurMs r?r.zRandom.triangulars  KKM |$*)DA q55aAaAcCdSjE!a%L000 !   JJJ sA AAcs |j} |}d|z }t|dz z|z }||zdz }|t| krn?|||zzS)NTr5rr4)r( NV_MAGICCONSTr{)r<musigmar(u1u2zZzzs r?r$zRandom.normalvariatesr BvvxBc*R/AQBd2hY AI~rAcs |j}|j}d|_|Y|tz}tdt d|z z}t ||z}t ||z|_|||zzS)Ngr5)r(r;TWOPIrr{_cos_sin)r<rrr(rZx2piZg2radrer?r z Random.gausss} 4 OO 968e#D$cFFHn!556ET U"A"4j50DOAI~rAcs@ t|j||Sr:)_expr$)r<rrr]r?r#zRandom.lognormvariate:s! D&&r5122rAcsJ td|jz  |z SNr5)r{r()r<Zlambdr>r?rzRandom.expovariateDs' S4;;=())E11rAcs |j}|dkrt|zSd|z }|td||zzz} |}tt|z}|||zz }|} | d||zz ks| d|z t |zkrnRd|z } | |zd| |zzz } |} | dkr|t | ztz} | S|t | z tz} | S)Ngư>rr5)r(rrr_pir_acos)r<rZkappar(rrrarrZdrZqZfZu3Zthetas r?r0zRandom.vonmisesvariateUs  D==668# # %K cAEk" "BS2XAQU ABC!a%K2#'T!W)<#<#< !G UsQU{ # VX 88%(]e+E %(]e+E rAcs |dks|dkr td|j}|dkrtd|zdz }|tz }||z} |}d|cxkrdksnd|z }t |d|z z |z } |t | z} ||z|z} ||| zz| z } | t zd| zz dks| t | kr| |zS|dkrt d|z  |zS |} t|ztz }|| z}|dkr |d|z z} nt ||z |z  } |}|dkr|| |dz zkr | |zS|t | kr | |zS{) Nr~z*gammavariate: alpha and beta must be > 0.0r5r3TgHz>gP?r6)rSr(rLOG4r{r SG_MAGICCONST_e)r<alphabetar(ZainvZbbbZcccrrvr=rrarrlps r?rzRandom.gammavariates  C<<43;;IJ J 3;; us*+D$,C$,CVXb,,,,9,,,,668^sRx)D0DGOGbL#'MA%}$sQw.#55d1gt8Oc\\vvx((4/ / FH%Z2%E88cEk*AAq1uo..AVXs77Q53;///t8O48^^t8OrAcsd |j|d}|r|||j|dzz SdS)Nr5r~)r)r<rry r?rzRandom.betavariatesB *   eS ) 1D--dC889 9srArcsJ |dkr td|dks|dkr|dkrdS|dkr|Std|j}|dkrt||kS|dkr||j|d|z z S||zdkrNdx}}t d|z }|s|S |t t ||z dzz }||kr|S|dz }5d }t ||zd|z z}d d |zz} d d| zzd|zz} ||zdz}dd| z z } |} | dz} dt| z } t d| z| z | z| z|z}|dks||krG|}| dkr|| kr|S|sWdd| z z|z}t|d|z z }t |dz|z}t|dzt||z dzz}d }|| | | zz | zz z}t|t|dzz t||z dzz |z zzkr|S )Nrzn must be non-negativer~r5z&p must be in the range 0.0 <= p <= 1.0r8rg$@TFgffffff?g= ףp=@gEJYga+e?{Gz?gq= ףp?g@r3gQ?gp= ף@gffffff@) rSr(rhr_log2rdr_fabsr{_lgamma)r<r_rr(r=rrMZsetup_completeZspqrlrKZvrrZusr`rrZlpqZmZhs r?rzRandom.binomialvariates  q5556 6 88qCxxCxxqCxxEF F 66&&(Q,' ' s77t++AsQw77 7 q54<<IAcAgA1VE&&(Oa/0144q55HQ AES1W%& 4#:  fqj 4!8 + ECK C!G^A HAuQxBa" q(A-12A1uuAATzza2gg ">a3.1a=)AEQ;'AENWQUQY%77!% !rBw-!+, ,AAw!ga!en,wq1uqy/AAQUcMQQQ5rAcs< d|jz }|d|z zS)Nr5gr)r<rrr]r?r%zRandom.paretovariate0s&A $++- TE\""rAcsZ d|jz }|t| d|z zzSr)r(r{)r<rrrrr?r1zRandom.weibullvariate7s3  $++- acDj111rAr:)Nr7)r~r5Nr~r5)r8r)%__name__ __module__ __qualname__rPr@r+r"r,rWrXrYr^r[BPFr\rZr&rir)r'rr-r*rr/r.r$r r#rr0rrrr%r1Z __classcell__)rNs@r?rrjst G$$$$$$LAAAAA66666B333 (9:3''''&-J===%)t'3'3'3'3R&&&... $$$/3]]]]]~#+tq#+#+#+#+#+P+++1111(*$$$$L333222"(((T???B8QQQQh### 2 2 2 2 2 2 2rArcs6eZdZ dZdZdZdZdZexZZ dS)rcs^ tjtddz tzS)NrBr9)rFrG_urandom RECIP_BPFrUrVr?r(zSystemRandom.randomPs"Ax{+q0I==rAcs |dkr td|dzdz}tjt|}||dz|z z S)Nrz#number of bits must be non-negativerBrf)rSrFrGr)r<r`Znumbytesr=rr?r!zSystemRandom.getrandbitsTsNH q55BC CEa< NN8H- .X\A%&&rAcs t|Sr:)rrgr>r?r&zSystemRandom.randbytes\s&{rAcs dSr:rQr<argsZkwdsr]r?r+zSystemRandom.seedbs FtrAcs td)Nz*System entropy source does not have state.)ZNotImplementedErrorrr]r?_notimplementedzSystemRandom._notimplementedfsK!"NOOrAN) rrrr(r!r&r+rr"r,rQrAr?rrGsm>>>''' PPP*)HxxxrArcsDddlm}m}ddlm}|}fdt d|D}|}||} ||| } t |} t|} t||z dd|djtd| | | | fzdS) Nr)stdevfmean) perf_countercsg|]} SrQrQ)rRrorfuncs r?ruz#_test_generator..s 2 2 2ADD$KKK 2rAz.3fz sec, z times z"avg %g, stddev %g, min %g, max %g ) Z statisticsrrZtimerrZminZmaxZprintr) r_rrrZmeanrZt0ZdataZt1Zxbarrrrs `` r?_test_generatorrs////////!!!!!! B 2 2 2 2 2q!1 2 2D B 4:D E$ E d)C t9D R"W A A A A A$-- A A ABB /4T2J JKKKKrA'cst|tdt|tdt|tdt|tdt|t dt|t dt|t dt|t dt|t dt|t dt|t d t|t d t|t d t|t d t|t d t|tdt|tdt|tddS)NrQr)ig333333?)idg?)rr5)皙?r5)rr3)rr5)g?r5)r5r5)r3r5)g4@r5)gi@r5)@r)r~r5gUUUUUU?) rr(r$r#r0rrr rr.)ZNrVr?_testrsAvr""A}j11A~z22A 33A 33A 44A|[11A|Z00A|Z00A|Z00A|Z00A|Z00A|Z00A|[11A|\22Auj))A{J//Az#89999rAZfork)Zafter_in_childZ__main__)r)_ZwarningsrrcZmathrr{rrrrrrrrzrrrrr rr rr rr rdr rrrrrrrZosrrZ_collections_abcrrvZoperatorrrhZ itertoolsrrxrrrryZ_osZ_randomrHrZ ImportErrorZhashlibZ__all__rrrrrrirrZ_instr+r(r/r.r'rr)r*r-rr$r#rr0rr rrr%r1r"r,r!r&rrZhasattrZregister_at_forkrrQrAr?rs*`#"""""LLLLLLLLLLLLLLGGGGGGGGGGGGEEEEEEEEEE@@@@@@@@@@""""""222222$$$$$$BBBBBBBB$$$$$$*))))))    :DDJs+  tCydd3i  #I V 2V 2V 2V 2V 2W^^V 2V 2z"*"*"*"*"*6"*"*X  zz  --    --  OO  -- --## %% ''!!   ''## %% >> >> OO LLL"::::0 73C 333 z EGGGG{***))))))))*sH)) H87H8