blob: b79377dd28dbdd7cd1f1ba534c818fc5372a9bfc [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{whrandom} ---
2 Floating point pseudo-random number generator.}
Fred Drakeb91e9341998-07-23 17:59:49 +00003\declaremodule{standard}{whrandom}
4
5\modulesynopsis{Floating point pseudo-random number generator.}
6
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00007
Guido van Rossum571391b1997-04-03 22:41:49 +00008This module implements a Wichmann-Hill pseudo-random number generator
9class that is also named \code{whrandom}. Instances of the
10\code{whrandom} class have the following methods:
Guido van Rossum571391b1997-04-03 22:41:49 +000011
12\begin{funcdesc}{choice}{seq}
13Chooses a random element from the non-empty sequence \var{seq} and returns it.
14\end{funcdesc}
15
Fred Drakecce10901998-03-17 06:33:25 +000016\begin{funcdesc}{randint}{a, b}
Guido van Rossum571391b1997-04-03 22:41:49 +000017Returns a random integer \var{N} such that \code{\var{a}<=\var{N}<=\var{b}}.
18\end{funcdesc}
19
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000020\begin{funcdesc}{random}{}
21Returns the next random floating point number in the range [0.0 ... 1.0).
22\end{funcdesc}
23
Fred Drakecce10901998-03-17 06:33:25 +000024\begin{funcdesc}{seed}{x, y, z}
Fred Drake37f15741999-11-10 16:21:37 +000025Initializes the random number generator from the integers \var{x},
26\var{y} and \var{z}. When the module is first imported, the random
27number is initialized using values derived from the current time.
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000028\end{funcdesc}
Guido van Rossum571391b1997-04-03 22:41:49 +000029
Fred Drakecce10901998-03-17 06:33:25 +000030\begin{funcdesc}{uniform}{a, b}
Guido van Rossum571391b1997-04-03 22:41:49 +000031Returns a random real number \var{N} such that \code{\var{a}<=\var{N}<\var{b}}.
32\end{funcdesc}
33
34When imported, the \code{whrandom} module also creates an instance of
35the \code{whrandom} class, and makes the methods of that instance
36available at the module level. Therefore one can write either
37\code{N = whrandom.random()} or:
Fred Drake19479911998-02-13 06:58:54 +000038\begin{verbatim}
Guido van Rossum571391b1997-04-03 22:41:49 +000039generator = whrandom.whrandom()
40N = generator.random()
Fred Drake19479911998-02-13 06:58:54 +000041\end{verbatim}
Fred Drake37f15741999-11-10 16:21:37 +000042
Guido van Rossume47da0a1997-07-17 16:34:52 +000043\begin{seealso}
Fred Drake37f15741999-11-10 16:21:37 +000044 \seemodule{random}{generators for various random distributions}
45 \seetext{Wichmann, B. A. \& Hill, I. D., ``Algorithm AS 183:
46 An efficient and portable pseudo-random number generator'',
47 \citetitle{Applied Statistics} 31 (1982) 188-190.}
Guido van Rossume47da0a1997-07-17 16:34:52 +000048\end{seealso}