blob: 7803184fba6c2c98440b5f6ebaccc9eb06f70296 [file] [log] [blame]
Guido van Rossum5fdeeea1994-01-02 01:22:07 +00001\section{Standard Module \sectcode{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:
Fred Drake19479911998-02-13 06:58:54 +00008\setindexsubitem{(in module whrandom)}
Guido van Rossum571391b1997-04-03 22:41:49 +00009
10\begin{funcdesc}{choice}{seq}
11Chooses a random element from the non-empty sequence \var{seq} and returns it.
12\end{funcdesc}
13
Fred Drakecce10901998-03-17 06:33:25 +000014\begin{funcdesc}{randint}{a, b}
Guido van Rossum571391b1997-04-03 22:41:49 +000015Returns a random integer \var{N} such that \code{\var{a}<=\var{N}<=\var{b}}.
16\end{funcdesc}
17
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000018\begin{funcdesc}{random}{}
19Returns the next random floating point number in the range [0.0 ... 1.0).
20\end{funcdesc}
21
Fred Drakecce10901998-03-17 06:33:25 +000022\begin{funcdesc}{seed}{x, y, z}
Guido van Rossum5fdeeea1994-01-02 01:22:07 +000023Initializes the random number generator from the integers
24\var{x},
25\var{y}
26and
27\var{z}.
28When the module is first imported, the random number is initialized
29using values derived from the current time.
30\end{funcdesc}
Guido van Rossum571391b1997-04-03 22:41:49 +000031
Fred Drakecce10901998-03-17 06:33:25 +000032\begin{funcdesc}{uniform}{a, b}
Guido van Rossum571391b1997-04-03 22:41:49 +000033Returns a random real number \var{N} such that \code{\var{a}<=\var{N}<\var{b}}.
34\end{funcdesc}
35
36When imported, the \code{whrandom} module also creates an instance of
37the \code{whrandom} class, and makes the methods of that instance
38available at the module level. Therefore one can write either
39\code{N = whrandom.random()} or:
Fred Drake19479911998-02-13 06:58:54 +000040\begin{verbatim}
Guido van Rossum571391b1997-04-03 22:41:49 +000041generator = whrandom.whrandom()
42N = generator.random()
Fred Drake19479911998-02-13 06:58:54 +000043\end{verbatim}
Guido van Rossume47da0a1997-07-17 16:34:52 +000044%
45\begin{seealso}
46\seemodule{random}{generators for various random distributions}
47\seetext{Wichmann, B. A. \& Hill, I. D., ``Algorithm AS 183:
48An efficient and portable pseudo-random number generator'',
Fred Drakecd14a871998-03-08 08:02:58 +000049\emph{Applied Statistics} 31 (1982) 188-190}
Guido van Rossume47da0a1997-07-17 16:34:52 +000050\end{seealso}