The whrandom
module, shown in Example 2-33, provides a pseudo-random number generator (based on an
algorithm by Wichmann and Hill, 1982). Unless you need several
generators that do not share internal state (for example, in a
multithreaded application), it’s better to use the functions in the
random
module
instead.
Example 2-34 shows how to create multiple generators by creating instances of the
whrandom
class.
Example 2-34. Using the whrandom Module to Create Multiple Random Generators
File: whrandom-example-2.py import whrandom # initialize all generators with the same seed rand1 = whrandom.whrandom(4,7,11) rand2 = whrandom.whrandom(4,7,11) rand3 = whrandom.whrandom(4,7,11) for i in range(5): print rand1.random(), rand2.random(), rand3.random()0.123993532536 0.123993532536 0.123993532536
0.180951499518 0.180951499518 0.180951499518
0.291924111809 0.291924111809 0.291924111809
0.952048889363 0.952048889363 0.952048889363
0.969794283643 0.969794283643 0.969794283643
18.226.34.25