mò %U²Ic@sudZdkZeideƒdfd„ƒYZeƒZeiZeiZeiZei Z ei Z ei Z dS(s"Wichman-Hill random number generator. Wichmann, B. A. & Hill, I. D. (1982) Algorithm AS 183: An efficient and portable pseudo-random number generator Applied Statistics 31 (1982) 188-190 see also: Correction to Algorithm AS 183 Applied Statistics 33 (1984) 123 McLeod, A. I. (1985) A remark on Algorithm AS 183 Applied Statistics 34 (1985),198-200 USE: whrandom.random() yields double precision random numbers uniformly distributed between 0 and 1. whrandom.seed(x, y, z) must be called before whrandom.random() to seed the generator There is also an interface to create multiple independent random generators, and to choose from other ranges. Multi-threading note: the random number generator used here is not thread-safe; it is possible that nearly simultaneous calls in different theads return the same random value. To avoid this, you have to use a lock around all calls. (I didn't want to slow this down in the serial case by using a lock here.) Ns?the whrandom module is deprecated; please use the random moduletwhrandomcBsetZdddd„Zdddd„Zd„Zd„Zd„Zd„Zdde dd „Z RS( NicCs|i|||ƒdS(sˆInitialize an instance. Without arguments, initialize from current time. With arguments (x, y, z), initialize from them.N(tselftseedtxtytz(RRRR((t%/data/zmath/lib/python2.4/whrandom.pyt__init__-scCs…t|ƒt|ƒjo"t|ƒjotdƒjnp td‚nd|jo djno9d|jo djnod|jo djnp td‚nd|jo|jo |jnozdk}t|iƒdƒ}t |d@|d?Aƒ}t |dƒ\}}t |dƒ\}}t |dƒ\}}n|pd|pd|pdf|_ dS( sRSet the seed from (x, y, z). These must be integers in the range [0, 256).isseeds must be integersisseeds must be in range(0, 256)Niÿÿÿii( ttypeRRRt TypeErrort ValueErrorttimetlongtttinttdivmodRt_seed(RRRRR R ((RR3sB Z * cCsj|i\}}}d|d}d|d}d|d}|||f|_|d|d|d d S( s3Get the next random number in the range [0.0, 1.0).i«i=vi¬icviªisvf30269.0f30307.0f30323.0f1.0N(RRRRR(RRRR((RtrandomEscCs||||iƒS(s(Get a random number in the range [a, b).N(tatbRR(RRR((RtuniformTscCs|i||dƒS(swGet a random integer in the range [a, b] including both end points. (Deprecated; use randrange below.)iN(Rt randrangeRR(RRR((RtrandintXscCs|t|iƒt|ƒƒS(s2Choose a random element from a non-empty sequence.N(tseqRRRtlen(RR((Rtchoice_sic Cs…||ƒ}||jo td‚n||jo2|djo||iƒ|ƒSntd‚n||ƒ}||jo td‚n|djo:||jo |||iƒ||ƒSntd‚n||ƒ} | |jo td‚n| djo||| d| }n1| djo||| d| }n td‚|djo td‚n|| ||iƒ|ƒS( sï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' and 'default' arguments.s!non-integer arg 1 for randrange()isempty range for randrange()s non-integer stop for randrange()is non-integer step for randrange()szero step for randrange()N( RtstarttistartR tstoptdefaultRRtistoptsteptisteptn( RRRRRRRR!RR ((RRcs4                     ( t__name__t __module__RRRRRRtNoneRR(((RR,s    ( t__doc__twarningstwarntDeprecationWarningRt_instRRRRRR( RR&RRRRRRR)((Rt?"s  ^