blob: bc7d402e03c97a343ed9a69bb4babcf0a766fd47 [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Standard Module \module{whrandom}}
Fred Drakeb91e9341998-07-23 17:59:49 +00002\declaremodule{standard}{whrandom}
3
4\modulesynopsis{Floating point pseudo-random number generator.}
5
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00006
Guido van Rossum571391b1997-04-03 22:41:49 +00007This module implements a Wichmann-Hill pseudo-random number generator
8class that is also named \code{whrandom}. Instances of the
9\code{whrandom} class have the following methods:
Guido van Rossum571391b1997-04-03 22:41:49 +000010
11\begin{funcdesc}{choice}{seq}
12Chooses a random element from the non-empty sequence \var{seq} and returns it.
13\end{funcdesc}
14
Fred Drakecce10901998-03-17 06:33:25 +000015\begin{funcdesc}{randint}{a, b}
Guido van Rossum571391b1997-04-03 22:41:49 +000016Returns a random integer \var{N} such that \code{\var{a}<=\var{N}<=\var{b}}.
17\end{funcdesc}
18
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000019\begin{funcdesc}{random}{}
20Returns the next random floating point number in the range [0.0 ... 1.0).
21\end{funcdesc}
22
Fred Drakecce10901998-03-17 06:33:25 +000023\begin{funcdesc}{seed}{x, y, z}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000024Initializes the random number generator from the integers
25\var{x},
26\var{y}
27and
28\var{z}.
29When the module is first imported, the random number is initialized
30using values derived from the current time.
31\end{funcdesc}
Guido van Rossum571391b1997-04-03 22:41:49 +000032
Fred Drakecce10901998-03-17 06:33:25 +000033\begin{funcdesc}{uniform}{a, b}
Guido van Rossum571391b1997-04-03 22:41:49 +000034Returns a random real number \var{N} such that \code{\var{a}<=\var{N}<\var{b}}.
35\end{funcdesc}
36
37When imported, the \code{whrandom} module also creates an instance of
38the \code{whrandom} class, and makes the methods of that instance
39available at the module level. Therefore one can write either
40\code{N = whrandom.random()} or:
Fred Drake19479911998-02-13 06:58:54 +000041\begin{verbatim}
Guido van Rossum571391b1997-04-03 22:41:49 +000042generator = whrandom.whrandom()
43N = generator.random()
Fred Drake19479911998-02-13 06:58:54 +000044\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +000045%
46\begin{seealso}
47\seemodule{random}{generators for various random distributions}
48\seetext{Wichmann, B. A. \& Hill, I. D., ``Algorithm AS 183:
49An efficient and portable pseudo-random number generator'',
Fred Drakecd14a871998-03-08 08:02:58 +000050\emph{Applied Statistics} 31 (1982) 188-190}
Guido van Rossume47da0a1997-07-17 16:34:52 +000051\end{seealso}