mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			74 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			TeX
		
	
	
	
	
	
			
		
		
	
	
			74 lines
		
	
	
	
		
			2.9 KiB
		
	
	
	
		
			TeX
		
	
	
	
	
	
| \section{\module{whrandom} ---
 | |
|          Pseudo-random number generator}
 | |
| 
 | |
| \declaremodule{standard}{whrandom}
 | |
| \modulesynopsis{Floating point pseudo-random number generator.}
 | |
| 
 | |
| \deprecated{2.1}{Use \refmodule{random} instead.}
 | |
| 
 | |
| \note{This module was an implementation detail of the
 | |
| \refmodule{random} module in releases of Python prior to 2.1.  It is
 | |
| no longer used.  Please do not use this module directly; use
 | |
| \refmodule{random} instead.}
 | |
| 
 | |
| This module implements a Wichmann-Hill pseudo-random number generator
 | |
| class that is also named \class{whrandom}.  Instances of the
 | |
| \class{whrandom} class conform to the Random Number Generator
 | |
| interface described in section \ref{rng-objects}.  They also offer the 
 | |
| following method, specific to the Wichmann-Hill algorithm:
 | |
| 
 | |
| \begin{methoddesc}[whrandom]{seed}{\optional{x, y, z}}
 | |
|   Initializes the random number generator from the integers \var{x},
 | |
|   \var{y} and \var{z}.  When the module is first imported, the random
 | |
|   number is initialized using values derived from the current time.
 | |
|   If \var{x}, \var{y}, and \var{z} are either omitted or \code{0}, the 
 | |
|   seed will be computed from the current system time.  If one or two
 | |
|   of the parameters are \code{0}, but not all three, the zero values
 | |
|   are replaced by ones.  This causes some apparently different seeds
 | |
|   to be equal, with the corresponding result on the pseudo-random
 | |
|   series produced by the generator.
 | |
| \end{methoddesc}
 | |
| 
 | |
| \begin{funcdesc}{choice}{seq}
 | |
| Chooses a random element from the non-empty sequence \var{seq} and returns it.
 | |
| \end{funcdesc}
 | |
| 
 | |
| \begin{funcdesc}{randint}{a, b}
 | |
| Returns a random integer \var{N} such that \code{\var{a}<=\var{N}<=\var{b}}.
 | |
| \end{funcdesc}
 | |
| 
 | |
| \begin{funcdesc}{random}{}
 | |
| Returns the next random floating point number in the range [0.0 ... 1.0).
 | |
| \end{funcdesc}
 | |
| 
 | |
| \begin{funcdesc}{seed}{x, y, z}
 | |
| Initializes the random number generator from the integers \var{x},
 | |
| \var{y} and \var{z}.  When the module is first imported, the random
 | |
| number is initialized using values derived from the current time.
 | |
| \end{funcdesc}
 | |
| 
 | |
| \begin{funcdesc}{uniform}{a, b}
 | |
| Returns a random real number \var{N} such that \code{\var{a}<=\var{N}<\var{b}}.
 | |
| \end{funcdesc}
 | |
| 
 | |
| When imported, the \module{whrandom} module also creates an instance of
 | |
| the \class{whrandom} class, and makes the methods of that instance
 | |
| available at the module level.  Therefore one can write either 
 | |
| \code{N = whrandom.random()} or:
 | |
| 
 | |
| \begin{verbatim}
 | |
| generator = whrandom.whrandom()
 | |
| N = generator.random()
 | |
| \end{verbatim}
 | |
| 
 | |
| Note that using separate instances of the generator leads to
 | |
| independent sequences of pseudo-random numbers.
 | |
| 
 | |
| \begin{seealso}
 | |
|   \seemodule{random}{Generators for various random distributions and
 | |
|                      documentation for the Random Number Generator
 | |
|                      interface.}
 | |
|   \seetext{Wichmann, B. A. \& Hill, I. D., ``Algorithm AS 183: 
 | |
|            An efficient and portable pseudo-random number generator'',
 | |
|            \citetitle{Applied Statistics} 31 (1982) 188-190.}
 | |
| \end{seealso}
 | 
