Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 1 | \section{Standard Module \sectcode{whrandom}} |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame^] | 2 | \label{module-whrandom} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 3 | \stmodindex{whrandom} |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 4 | |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 5 | This module implements a Wichmann-Hill pseudo-random number generator |
| 6 | class that is also named \code{whrandom}. Instances of the |
| 7 | \code{whrandom} class have the following methods: |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 8 | \renewcommand{\indexsubitem}{(in module whrandom)} |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 9 | |
| 10 | \begin{funcdesc}{choice}{seq} |
| 11 | Chooses a random element from the non-empty sequence \var{seq} and returns it. |
| 12 | \end{funcdesc} |
| 13 | |
| 14 | \begin{funcdesc}{randint}{a\, b} |
| 15 | Returns a random integer \var{N} such that \code{\var{a}<=\var{N}<=\var{b}}. |
| 16 | \end{funcdesc} |
| 17 | |
Guido van Rossum | 5fdeeea | 1994-01-02 01:22:07 +0000 | [diff] [blame] | 18 | \begin{funcdesc}{random}{} |
| 19 | Returns the next random floating point number in the range [0.0 ... 1.0). |
| 20 | \end{funcdesc} |
| 21 | |
| 22 | \begin{funcdesc}{seed}{x\, y\, z} |
| 23 | Initializes the random number generator from the integers |
| 24 | \var{x}, |
| 25 | \var{y} |
| 26 | and |
| 27 | \var{z}. |
| 28 | When the module is first imported, the random number is initialized |
| 29 | using values derived from the current time. |
| 30 | \end{funcdesc} |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 31 | |
| 32 | \begin{funcdesc}{uniform}{a\, b} |
| 33 | Returns a random real number \var{N} such that \code{\var{a}<=\var{N}<\var{b}}. |
| 34 | \end{funcdesc} |
| 35 | |
| 36 | When imported, the \code{whrandom} module also creates an instance of |
| 37 | the \code{whrandom} class, and makes the methods of that instance |
| 38 | available at the module level. Therefore one can write either |
| 39 | \code{N = whrandom.random()} or: |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame^] | 40 | \bcode\begin{verbatim} |
Guido van Rossum | 571391b | 1997-04-03 22:41:49 +0000 | [diff] [blame] | 41 | generator = whrandom.whrandom() |
| 42 | N = generator.random() |
Guido van Rossum | e47da0a | 1997-07-17 16:34:52 +0000 | [diff] [blame^] | 43 | \end{verbatim}\ecode |
| 44 | % |
| 45 | \begin{seealso} |
| 46 | \seemodule{random}{generators for various random distributions} |
| 47 | \seetext{Wichmann, B. A. \& Hill, I. D., ``Algorithm AS 183: |
| 48 | An efficient and portable pseudo-random number generator'', |
| 49 | Applied Statistics 31 (1982) 188-190} |
| 50 | \end{seealso} |