{G_Tc@sQddlZddlZddlZddlZddlZddlmZmZmZm Z m Z ddl m Z ddl mZdejfdYZdefdYZd efd YZd efd YZd eddZdejfdYZdejfdYZddZedkrMedendS(iN(tlogtexptpitfsumtsin(treduce(t test_supportt TestBasicOpscBs}eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d ZRS( cCs&gt|D]}|jj^q S(s0Helper function to make a list of random numbers(txrangetgentrandom(tselftnti((s,/usr/local/lib/python2.7/test/test_random.pyt randomlistscCsY|jj|jj}tjd|jj|jj}|j||dS(Ng?(R tseedtgetstatettimetsleeptassertNotEqual(R tstate1tstate2((s,/usr/local/lib/python2.7/test/test_random.pyt test_autoseeds    cCs^d}|jj|jj}|j|}|jj||j||j|dS(Ni(R RRRtsetstatet assertEqual(R tNtstatetrandseq((s,/usr/local/lib/python2.7/test/test_random.pyttest_saverestores  cCsxKdddddddddd dd td g D]}|jj|q4Wx<td tddgD]}|jt|jj|qjW|jt|jjdd|jtt|jgdS(Nililili igQ @y@tatabcitoneil Fx:^Vl Fx:^Vl Fx:^Vy?@( tNonettupleR Rtrangetdictt assertRaisest TypeErrorttype(R targ((s,/usr/local/lib/python2.7/test/test_random.pyt test_seedargs#s"c Cs|jj|jj}|jjd|jj}|j|||jjd|jj}|j||tjdt7|jt |jj|jt |jjddWdQXdS(Nidtquietii( R RRt jumpaheadRRtcheck_py3k_warningstTrueR$R%(R RRtstate3((s,/usr/local/lib/python2.7/test/test_random.pyttest_jumpahead,s cCsZ|jjd|jjdx3tdD]%}|jj}|j|dq-WdS(Ni li)m` ig?(R RR*R"R t assertLess(R R tval((s,/usr/local/lib/python2.7/test/test_random.pyt#test_jumpahead_produces_valid_state:s cCsd}t|}x~t|dD]l}|jj||}|jt||t|}|jt|||j|t|kq#W|j|jjgdgdS(Nidii(RR tsampleRtlentsett assertTrue(R Rt populationtktstuniq((s,/usr/local/lib/python2.7/test/test_random.pyt test_sampleBs  c Csd}t|}d}d}xt|D]|}|||||}i}xSt|D];}d|t|jj||tsi( R R2R#tfromkeysR"RR5R&R;tsortR(R RRtdR7tsamptx((s,/usr/local/lib/python2.7/test/test_random.pyttest_sample_on_dictsis2 ! cCsxd D]}|jj||jj}|jjdd}|jj||jj}|jjdd}|j|||j||qWdS( Nii i{ii90i@i i(ii i{ii90i@i (R RR tgaussR(R Rtx1ty1tx2ty2((s,/usr/local/lib/python2.7/test/test_random.pyt test_gauss}s cCstj|j}gtdD]}|jj^q}tj|}gtdD]}|j^qV}|j||dS(Ni (tpickletdumpsR RR tloadsR(R RR torigseqtnewgent restoredseq((s,/usr/local/lib/python2.7/test/test_random.pyt test_picklings (%cCstd d d g}x^|D]V\}}ttj|d}tj|}|j|j|jd|qWdS( Ns randv2_32.pcki s randv2_64.pckibs randv3.pckiWtrbi(s randv2_32.pcki (s randv2_64.pckib(s randv3.pckiW(topenRtfindfileRUtloadtcloseRt randrange(R tfilestfiletvaluetftr((s,/usr/local/lib/python2.7/test/test_random.pyttest_bug_1727780s  (t__name__t __module__RRRR(R.R1R:RCRFRNRTR[Rg(((s,/usr/local/lib/python2.7/test/test_random.pyR s          tWichmannHill_TestBasicOpscBs8eZejZdZdZdZdZRS(cCs|jt|jjddS(Ni(iNN(R$t ValueErrorR RR (R ((s,/usr/local/lib/python2.7/test/test_random.pyttest_setstate_first_argscCsd}|jj}|jj||jj}|jj|x!t|D]}|jjqQW|jj}|j||dS(Ni(R RR*R RRR(R RR8tr1R tr2((s,/usr/local/lib/python2.7/test/test_random.pyttest_strong_jumpaheadscCsxd D]}|jj||jj}|jjdd}|jj||jj}|jjdd}|j|||j||qWdS( Nii i{ii90i@i i(ii i{ii90i@i (R twhseedR ROR(R RRPRQRRRS((s,/usr/local/lib/python2.7/test/test_random.pyttest_gauss_with_whseeds c Cs@tj.tjdd|jt|jjdWdQXdS(NterrorsUnderlying randomii<I(twarningstcatch_warningstfilterwarningsR$t UserWarningR Ra(R ((s,/usr/local/lib/python2.7/test/test_random.pyt test_bigrands ( RhRiR t WichmannHillR RlRoRqRw(((s,/usr/local/lib/python2.7/test/test_random.pyRjs    tSystemRandom_TestBasicOpscBseZejZdZdZdZdZdZ dZ dZ dZ dZ d Zd Zeed ZRS( cCs|jjdS(N(R R(R ((s,/usr/local/lib/python2.7/test/test_random.pyRscCs3|jt|jj|jt|jjddS(N(R$tNotImplementedErrorR RRR (R ((s,/usr/local/lib/python2.7/test/test_random.pyRscCs|jjddS(Nid(R R(R ((s,/usr/local/lib/python2.7/test/test_random.pyR(scCs|jjddS(Nid(R R*(R ((s,/usr/local/lib/python2.7/test/test_random.pyR.scCs6d|j_|jjd|j|jjddS(Nid(R R t gauss_nextRR(R ((s,/usr/local/lib/python2.7/test/test_random.pyRTs cCs|jttj|jdS(N(R$RzRURVR (R ((s,/usr/local/lib/python2.7/test/test_random.pyR[scCsXd}d}x1tdD]#}|t|jj|O}qW|j||ddS(Nii5iidiI (RR;R R R(R tspantcumR ((s,/usr/local/lib/python2.7/test/test_random.pyttest_53_bits_per_floats !cCszd}d}xStdD]E}|jj|}|jd|koN|kn||O}qW|j||ddS(Niiiidil" (RR RaR5R(R R|R}R Rf((s,/usr/local/lib/python2.7/test/test_random.pyRws#c Csxddddddddd g D]z}|jjd |d }|jjd |}||krjq"n|j||jj||ko|knq"WdS( Ni(iPiiiiiwii&i(R RaR5(R R tstarttstop((s,/usr/local/lib/python2.7/test/test_random.pyttest_bigrand_rangess ( c Cs}xvdd d fd dfgD]Y\}}|jtt||tgtdD]}|jj||^qPqWdS(Niiii<id(iiIIIIIIII(RR4R"RR Ra(R RRR ((s,/usr/local/lib/python2.7/test/test_random.pyttest_rangelimitss(cCsZxJtddD]9}|jd|jj|koCd|knqW|jj}x}dddddddd d d d d ddgD]K}d}x$tdD]}|||O}qW|j|d|dqW|jt|jj|jt|jjdd|jt|jjd|jt|jjd|jt|jjddS(Niiiiiiii i4i5i6iwiiiidig333333$@(RR5R t getrandbitsRR$R%Rk(R R7tgetbitsR|R}R ((s,/usr/local/lib/python2.7/test/test_random.pyttest_genrandbitss7 7cCsLxEtddD]4}d|>}|d}|d||d}|j|||j|d|dk||d7}|d||d}|j|||dg|jd||kod|dkn||d?8}|d||d}|j|||jd||ko>d|dknqWdS(NiilgrZ| ?ii(RRR5tassertIn(R t_logR;R R tnumbitsR7((s,/usr/local/lib/python2.7/test/test_random.pyttest_randbelow_logics  /(RhRiR t SystemRandomR RRR(R.RTR[R~RwRRRRR;R(((s,/usr/local/lib/python2.7/test/test_random.pyRys           tMersenneTwister_TestBasicOpscBseZejZdZdZdZdZdZ dZ dZ dZ dZ d Zeed Zd ZRS( cCs|jt|jjddS(Ni(iNN(R$RkR RR (R ((s,/usr/local/lib/python2.7/test/test_random.pyRl4scCs|jt|jjd|jt|jjdd df|jt|jjdd ddf|jt|jjdd dd dfdS( NiiiRiqiip(iNN(iii(R(i(R(R$R%R RR Rk(R ((s,/usr/local/lib/python2.7/test/test_random.pyttest_setstate_middle_arg7s"&c Csddddddddd d g }|jjd ddd|jdd}x3t||D]"\}}|j||ddqcWdS(Ng>FdV?gwR1ۉ?gQ"?g~5?gmb?gYKbX?gH,r̊?gV8?gOֶ?g4Ԗ?l#qlGai lfi@l$i`iitplacesill`&l'R(R RRtziptassertAlmostEqual(R RAtactualRte((s,/usr/local/lib/python2.7/test/test_random.pyttest_referenceImplementationAs c Csddlm}ddddddd d d d g }|jjd ddd|jdd}x<t||D]+\}}|jt||d|qsWdS(Ni(tldexpl#1,ulwbl'lJXluak~[l@"p1ylsV%bX$lE3EJlVblaoekl4)[vl#qlGai lfi@l$i`iii5ll`&l'R(tmathRR RRRRtlong(R RRARRR((s,/usr/local/lib/python2.7/test/test_random.pyt$test_strong_reference_implementation`s cCs"dd>d}|jj|dS(Nli'iii8(R R(R R((s,/usr/local/lib/python2.7/test/test_random.pyttest_long_seedvscCsXd}d}x1tdD]#}|t|jj|O}qW|j||ddS(Nii5iidiI (RR;R R R(R R|R}R ((s,/usr/local/lib/python2.7/test/test_random.pyR~s !cCszd}d}xStdD]E}|jj|}|jd|koN|kn||O}qW|j||ddS(Niiiidil" (RR RaR5R(R R|R}R Rf((s,/usr/local/lib/python2.7/test/test_random.pyRws#c Csxddddddddd g D]z}|jjd |d }|jjd |}||krjq"n|j||jj||ko|knq"WdS( Ni(iPiiiiiwii&i(R RaR5(R R RR((s,/usr/local/lib/python2.7/test/test_random.pyRs ( c Cs}xvdd d fd dfgD]Y\}}|jtt||tgtdD]}|jj||^qPqWdS(Niiii<id(iiIIIIIIII(RR4R"RR Ra(R RRR ((s,/usr/local/lib/python2.7/test/test_random.pyRs(cCs|jjd|j|jjddxJtddD]9}|jd|jj|kood|knq<W|jj}x}dddd d d d d d dddddgD]K}d}x$tdD]}|||O}qW|j|d|dqW|jt|jj|jt|jjd|jt|jjdd|jt|jjd|jt|jjddS(NiidlS!m.vFX Oiiiiiiii i4i5i6iwiiiRi( R RRRRR5R$R%Rk(R R7RR|R}R ((s,/usr/local/lib/python2.7/test/test_random.pyRs 7 7cCsLxEtddD]4}d|>}|d}|d||d}|j|||j|d|dk||d7}|d||d}|j|||dg|jd||kod|dkn||d?8}|d||d}|j|||jd||ko>d|dknqWdS(NiilgrZ| ?ii(RRR5R(R RR;R R RR7((s,/usr/local/lib/python2.7/test/test_random.pyRs  /cCsid}d}d}|jj|||}|j||koG|kn|j|||ddS(NIl Fx:^Vi8i(R RaR5R(R RRtstepRM((s,/usr/local/lib/python2.7/test/test_random.pyttest_randrange_bug_1590891s #(RhRiR tRandomR RlRRRRR~RwRRRRR;RR(((s,/usr/local/lib/python2.7/test/test_random.pyR1s        g@g?c Cs|dkr,ttt|td|S|d}||dt||tdd|d|dd|dd |d d |d d |dd|dd|dg S(Ng?g?g@g ?g ö)$@g&Ԏg ta@g@gQfg@g>@~)@g@gA~g@g~\>g@giE>g@(RRtgammaRR(tztsqrt2pitaz((s,/usr/local/lib/python2.7/test/test_random.pyRs         tTestDistributionscBs5eZdZdZdZdZdZRS(cCstj}gtdD]}|j^qdgd}|j|_|jdd|j|_|jd|j|_|jd|j|_|jdd|j|_|jdd|j|_|j dd|j|_|j dd|j|_|j dd|j|_|jdd|j|_|j dd|j|_|j dd|j|_|j dd|j|_|j d d |j|_|jdddd dS( Ni2giii g?g{Gz?gi@g@(R RRR?tuniformt paretovariatet expovariatetweibullvariatetvonmisesvariatet normalvariateROtlognormvariatet gammavariatet betavariatet triangular(R tgR RM((s,/usr/local/lib/python2.7/test/test_random.pyttest_zeroinputss< 0              c Cs6tj}d}gtd|D]}|t|^q"}x|jdddddf|jddddfd d d d d f|jddd ddf|jdttddf|j dddddd f|j d!t dddt dddt ddddfgD]\}}}}|j |_g} xEtt |D]1}y| j||WqXtk rqXXqXWd} } x*| D]"} | | 7} | | |d7} qWt | }|j| ||dddd|j|f|j| |d|dddd|j|fq WdS("Niig?g$@ii gg@g@g"@g@g2@g?gGz?iig@Rtmsgs%s%r(g?g$@g&@g"@g@T@(g?g@(gGz?i(g@g@g@g0@g@(g?g@(R RRtfloatRRRRRRRRR?R3tappendt IndexErrorRRh( R RRR RMtvariatetargstmut sigmasqrdtyts1ts2R((s,/usr/local/lib/python2.7/test/test_random.pyt test_avg_stds8 ,+@      cCsHtj}d}x/|jddf|jddf|jd df|jtdfdf|jdtdfdf|jd df|jd df|jtd dfdf|j d df|j tdfdf|j dtdfdf|j d dfg D]<\}}}x*t |D]}|j |||q WqWdS(Nidg$@tinfgg@g?(g$@g$@(g$@g$@(g$@g$@g$@(g$@g(gg(g$@g(gg$@(R RRRRRRRORRRRR"R(R RRRRRAR ((s,/usr/local/lib/python2.7/test/test_random.pyt test_constants" "c Cstj}d}xd D]{}xrd D]j}xat|D]S}|j||}|jd|koqtjknd d j|||q9Wq&WqWdS( Nidgg?g@g@gffffff@g@@iRsCvonmisesvariate({}, {}) produced a result {} out of range [0, 2*pi](gg?g@g@(ggffffff@g@@(R RR"RR5tTWOPItformat(R RRRtkappat_R2((s,/usr/local/lib/python2.7/test/test_random.pyttest_von_mises_range.s   cCs$tjddtjdddS(Nig4&k Cg}Ô%IT(R R(R ((s,/usr/local/lib/python2.7/test/test_random.pyttest_von_mises_large_kappa<s(RhRiRRRRR(((s,/usr/local/lib/python2.7/test/test_random.pyRs    t TestModulecBs#eZdZdZdZRS(cCsP|jtjd|jtjd|jtjd|jtjddS(Ng3?r?g.DT!@g9B.?gtY@(RR t NV_MAGICCONSTRtLOG4t SG_MAGICCONST(R ((s,/usr/local/lib/python2.7/test/test_random.pyttestMagicConstantsCscCs,|jttjtttkdS(N(R5R4R t__all__tdir(R ((s,/usr/local/lib/python2.7/test/test_random.pyt test__all__IscCs*dtjfdY}|dddS(NtSubclasscBseZddZRS(cSstjj|dS(N(R Rt__init__(R tnewarg((s,/usr/local/lib/python2.7/test/test_random.pyRPsN(RhRiR R(((s,/usr/local/lib/python2.7/test/test_random.pyROsRi(R R(R R((s,/usr/local/lib/python2.7/test/test_random.pyt test_random_subclass_with_kwargsMs(RhRiRRR(((s,/usr/local/lib/python2.7/test/test_random.pyRBs  cCsttttg}ytjjWntk r9nX|jtt j |ddl }|rt |drdgd}x7tt|D]#}t j ||j||s"     (*e\