1 \section{\module{whrandom
} ---
2 Pseudo-random number generator
}
4 \declaremodule{standard
}{whrandom
}
5 \modulesynopsis{Floating point pseudo-random number generator.
}
8 This module implements a Wichmann-Hill pseudo-random number generator
9 class that is also named
\class{whrandom
}. Instances of the
10 \class{whrandom
} class conform to the Random Number Generator
11 interface described in section
\ref{rng-objects
}. They also offer the
12 following method, specific to the Wichmann-Hill algorithm:
14 \begin{methoddesc
}[whrandom
]{seed
}{\optional{x, y, z
}}
15 Initializes the random number generator from the integers
\var{x
},
16 \var{y
} and
\var{z
}. When the module is first imported, the random
17 number is initialized using values derived from the current time.
18 If
\var{x
},
\var{y
}, and
\var{z
} are either omitted or
\code{0}, the
19 seed will be computed from the current system time. If one or two
20 of the parameters are
\code{0}, but not all three, the zero values
21 are replaced by ones. This causes some apparently different seeds
22 to be equal, with the corresponding result on the pseudo-random
23 series produced by the generator.
26 \begin{funcdesc
}{choice
}{seq
}
27 Chooses a random element from the non-empty sequence
\var{seq
} and returns it.
30 \begin{funcdesc
}{randint
}{a, b
}
31 Returns a random integer
\var{N
} such that
\code{\var{a
}<=
\var{N
}<=
\var{b
}}.
34 \begin{funcdesc
}{random
}{}
35 Returns the next random floating point number in the range
[0.0 ...
1.0).
38 \begin{funcdesc
}{seed
}{x, y, z
}
39 Initializes the random number generator from the integers
\var{x
},
40 \var{y
} and
\var{z
}. When the module is first imported, the random
41 number is initialized using values derived from the current time.
44 \begin{funcdesc
}{uniform
}{a, b
}
45 Returns a random real number
\var{N
} such that
\code{\var{a
}<=
\var{N
}<
\var{b
}}.
48 When imported, the
\module{whrandom
} module also creates an instance of
49 the
\class{whrandom
} class, and makes the methods of that instance
50 available at the module level. Therefore one can write either
51 \code{N = whrandom.random()
} or:
54 generator = whrandom.whrandom()
55 N = generator.random()
58 Note that using separate instances of the generator leads to
59 independent sequences of pseudo-random numbers.
62 \seemodule{random
}{Generators for various random distributions and
63 documentation for the Random Number Generator
65 \seetext{Wichmann, B. A. \& Hill, I. D., ``Algorithm AS
183:
66 An efficient and portable pseudo-random number generator'',
67 \citetitle{Applied Statistics
} 31 (
1982)
188-
190.
}