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