blob: 0645b6f7c1221af05ddaa0f3025a3522d987e17e [file] [log] [blame]
Fred Drake3a0351c1998-04-04 07:23:21 +00001\section{Standard Module \module{whrandom}}
Guido van Rossume47da0a1997-07-17 16:34:52 +00002\label{module-whrandom}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00003\stmodindex{whrandom}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00004
Guido van Rossum571391b1997-04-03 22:41:49 +00005This module implements a Wichmann-Hill pseudo-random number generator
6class that is also named \code{whrandom}. Instances of the
7\code{whrandom} class have the following methods:
Guido van Rossum571391b1997-04-03 22:41:49 +00008
9\begin{funcdesc}{choice}{seq}
10Chooses a random element from the non-empty sequence \var{seq} and returns it.
11\end{funcdesc}
12
Fred Drakecce10901998-03-17 06:33:25 +000013\begin{funcdesc}{randint}{a, b}
Guido van Rossum571391b1997-04-03 22:41:49 +000014Returns a random integer \var{N} such that \code{\var{a}<=\var{N}<=\var{b}}.
15\end{funcdesc}
16
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000017\begin{funcdesc}{random}{}
18Returns the next random floating point number in the range [0.0 ... 1.0).
19\end{funcdesc}
20
Fred Drakecce10901998-03-17 06:33:25 +000021\begin{funcdesc}{seed}{x, y, z}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000022Initializes the random number generator from the integers
23\var{x},
24\var{y}
25and
26\var{z}.
27When the module is first imported, the random number is initialized
28using values derived from the current time.
29\end{funcdesc}
Guido van Rossum571391b1997-04-03 22:41:49 +000030
Fred Drakecce10901998-03-17 06:33:25 +000031\begin{funcdesc}{uniform}{a, b}
Guido van Rossum571391b1997-04-03 22:41:49 +000032Returns a random real number \var{N} such that \code{\var{a}<=\var{N}<\var{b}}.
33\end{funcdesc}
34
35When imported, the \code{whrandom} module also creates an instance of
36the \code{whrandom} class, and makes the methods of that instance
37available at the module level. Therefore one can write either
38\code{N = whrandom.random()} or:
Fred Drake19479911998-02-13 06:58:54 +000039\begin{verbatim}
Guido van Rossum571391b1997-04-03 22:41:49 +000040generator = whrandom.whrandom()
41N = generator.random()
Fred Drake19479911998-02-13 06:58:54 +000042\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +000043%
44\begin{seealso}
45\seemodule{random}{generators for various random distributions}
46\seetext{Wichmann, B. A. \& Hill, I. D., ``Algorithm AS 183:
47An efficient and portable pseudo-random number generator'',
Fred Drakecd14a871998-03-08 08:02:58 +000048\emph{Applied Statistics} 31 (1982) 188-190}
Guido van Rossume47da0a1997-07-17 16:34:52 +000049\end{seealso}