| 
									
										
										
										
											1998-08-10 19:42:37 +00:00
										 |  |  | \section{\module{whrandom} --- | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  |          Pseudo-random number generator} | 
					
						
							| 
									
										
										
										
											1998-07-23 17:59:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | \declaremodule{standard}{whrandom} | 
					
						
							| 
									
										
										
										
											1998-07-23 17:59:49 +00:00
										 |  |  | \modulesynopsis{Floating point pseudo-random number generator.} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-02-03 01:12:44 +00:00
										 |  |  | \deprecated{2.1}{Use \refmodule{random} instead.} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-10-20 04:24:09 +00:00
										 |  |  | \note{This module was an implementation detail of the | 
					
						
							| 
									
										
										
										
											2001-02-03 01:12:44 +00:00
										 |  |  | \refmodule{random} module in releases of Python prior to 2.1.  It is | 
					
						
							|  |  |  | no longer used.  Please do not use this module directly; use | 
					
						
							| 
									
										
										
										
											2001-10-20 04:24:09 +00:00
										 |  |  | \refmodule{random} instead.} | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-04-03 22:41:49 +00:00
										 |  |  | This module implements a Wichmann-Hill pseudo-random number generator | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | 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} | 
					
						
							| 
									
										
										
										
											1997-04-03 22:41:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | \begin{funcdesc}{choice}{seq} | 
					
						
							|  |  |  | Chooses a random element from the non-empty sequence \var{seq} and returns it. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-03-17 06:33:25 +00:00
										 |  |  | \begin{funcdesc}{randint}{a, b} | 
					
						
							| 
									
										
										
										
											1997-04-03 22:41:49 +00:00
										 |  |  | Returns a random integer \var{N} such that \code{\var{a}<=\var{N}<=\var{b}}. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | \begin{funcdesc}{random}{} | 
					
						
							|  |  |  | Returns the next random floating point number in the range [0.0 ... 1.0). | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-03-17 06:33:25 +00:00
										 |  |  | \begin{funcdesc}{seed}{x, y, z} | 
					
						
							| 
									
										
										
										
											1999-11-10 16:21:37 +00:00
										 |  |  | 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. | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | \end{funcdesc} | 
					
						
							| 
									
										
										
										
											1997-04-03 22:41:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-03-17 06:33:25 +00:00
										 |  |  | \begin{funcdesc}{uniform}{a, b} | 
					
						
							| 
									
										
										
										
											1997-04-03 22:41:49 +00:00
										 |  |  | Returns a random real number \var{N} such that \code{\var{a}<=\var{N}<\var{b}}. | 
					
						
							|  |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | When imported, the \module{whrandom} module also creates an instance of | 
					
						
							|  |  |  | the \class{whrandom} class, and makes the methods of that instance | 
					
						
							| 
									
										
										
										
											1997-04-03 22:41:49 +00:00
										 |  |  | available at the module level.  Therefore one can write either  | 
					
						
							|  |  |  | \code{N = whrandom.random()} or: | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-02-13 06:58:54 +00:00
										 |  |  | \begin{verbatim} | 
					
						
							| 
									
										
										
										
											1997-04-03 22:41:49 +00:00
										 |  |  | generator = whrandom.whrandom() | 
					
						
							|  |  |  | N = generator.random() | 
					
						
							| 
									
										
										
										
											1998-02-13 06:58:54 +00:00
										 |  |  | \end{verbatim} | 
					
						
							| 
									
										
										
										
											1999-11-10 16:21:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | Note that using separate instances of the generator leads to | 
					
						
							|  |  |  | independent sequences of pseudo-random numbers. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1997-07-17 16:34:52 +00:00
										 |  |  | \begin{seealso} | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  |   \seemodule{random}{Generators for various random distributions and | 
					
						
							|  |  |  |                      documentation for the Random Number Generator | 
					
						
							|  |  |  |                      interface.} | 
					
						
							| 
									
										
										
										
											1999-11-10 16:21:37 +00:00
										 |  |  |   \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.} | 
					
						
							| 
									
										
										
										
											1997-07-17 16:34:52 +00:00
										 |  |  | \end{seealso} |