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