blob: 8df1b772b6043c3e6b64dbe2592d8d4c85c3dc58 [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}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000025Initializes the random number generator from the integers
26\var{x},
27\var{y}
28and
29\var{z}.
30When the module is first imported, the random number is initialized
31using values derived from the current time.
32\end{funcdesc}
Guido van Rossum571391b1997-04-03 22:41:49 +000033
Fred Drakecce10901998-03-17 06:33:25 +000034\begin{funcdesc}{uniform}{a, b}
Guido van Rossum571391b1997-04-03 22:41:49 +000035Returns a random real number \var{N} such that \code{\var{a}<=\var{N}<\var{b}}.
36\end{funcdesc}
37
38When imported, the \code{whrandom} module also creates an instance of
39the \code{whrandom} class, and makes the methods of that instance
40available at the module level. Therefore one can write either
41\code{N = whrandom.random()} or:
Fred Drake19479911998-02-13 06:58:54 +000042\begin{verbatim}
Guido van Rossum571391b1997-04-03 22:41:49 +000043generator = whrandom.whrandom()
44N = generator.random()
Fred Drake19479911998-02-13 06:58:54 +000045\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +000046%
47\begin{seealso}
48\seemodule{random}{generators for various random distributions}
49\seetext{Wichmann, B. A. \& Hill, I. D., ``Algorithm AS 183:
50An efficient and portable pseudo-random number generator'',
Fred Drakecd14a871998-03-08 08:02:58 +000051\emph{Applied Statistics} 31 (1982) 188-190}
Guido van Rossume47da0a1997-07-17 16:34:52 +000052\end{seealso}