mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Remove the deprecated whrandom module.
This commit is contained in:
		
							parent
							
								
									2238fc6b67
								
							
						
					
					
						commit
						784ab76c87
					
				
					 6 changed files with 8 additions and 257 deletions
				
			
		| 
						 | 
					@ -124,7 +124,6 @@ and how to embed it in other applications.
 | 
				
			||||||
\input{libmath}
 | 
					\input{libmath}
 | 
				
			||||||
\input{libcmath}
 | 
					\input{libcmath}
 | 
				
			||||||
\input{librandom}
 | 
					\input{librandom}
 | 
				
			||||||
\input{libwhrandom}
 | 
					 | 
				
			||||||
\input{libbisect}
 | 
					\input{libbisect}
 | 
				
			||||||
\input{libcollections}
 | 
					\input{libcollections}
 | 
				
			||||||
\input{libheapq}
 | 
					\input{libheapq}
 | 
				
			||||||
| 
						 | 
					@ -354,7 +353,6 @@ and how to embed it in other applications.
 | 
				
			||||||
%\input{libcmpcache}
 | 
					%\input{libcmpcache}
 | 
				
			||||||
%\input{libcmp}
 | 
					%\input{libcmp}
 | 
				
			||||||
%\input{libni}
 | 
					%\input{libni}
 | 
				
			||||||
%\input{librand}
 | 
					 | 
				
			||||||
%\input{libregex}
 | 
					%\input{libregex}
 | 
				
			||||||
%\input{libregsub}
 | 
					%\input{libregsub}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,31 +0,0 @@
 | 
				
			||||||
\section{\module{rand} ---
 | 
					 | 
				
			||||||
         None}
 | 
					 | 
				
			||||||
\declaremodule{standard}{rand}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\modulesynopsis{None}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
The \code{rand} module simulates the C library's \code{rand()}
 | 
					 | 
				
			||||||
interface, though the results aren't necessarily compatible with any
 | 
					 | 
				
			||||||
given library's implementation.  While still supported for
 | 
					 | 
				
			||||||
compatibility, the \code{rand} module is now considered obsolete; if
 | 
					 | 
				
			||||||
possible, use the \code{whrandom} module instead.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{funcdesc}{choice}{seq}
 | 
					 | 
				
			||||||
Returns a random element from the sequence \var{seq}.
 | 
					 | 
				
			||||||
\end{funcdesc}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{funcdesc}{rand}{}
 | 
					 | 
				
			||||||
Return a random integer between 0 and 32767, inclusive.
 | 
					 | 
				
			||||||
\end{funcdesc}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{funcdesc}{srand}{seed}
 | 
					 | 
				
			||||||
Set a starting seed value for the random number generator; \var{seed}
 | 
					 | 
				
			||||||
can be an arbitrary integer. 
 | 
					 | 
				
			||||||
\end{funcdesc}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
\begin{seealso}
 | 
					 | 
				
			||||||
  \seemodule{random}{Python's interface to random number generators.}
 | 
					 | 
				
			||||||
  \seemodule{whrandom}{The random number generator used by default.}
 | 
					 | 
				
			||||||
\end{seealso}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -1,74 +0,0 @@
 | 
				
			||||||
\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}
 | 
					 | 
				
			||||||
| 
						 | 
					@ -4777,7 +4777,7 @@ packages. For example:
 | 
				
			||||||
\item The \ulink{\module{xmlrpclib}}{../lib/module-xmlrpclib.html} and
 | 
					\item The \ulink{\module{xmlrpclib}}{../lib/module-xmlrpclib.html} and
 | 
				
			||||||
  \ulink{\module{SimpleXMLRPCServer}}{../lib/module-SimpleXMLRPCServer.html}
 | 
					  \ulink{\module{SimpleXMLRPCServer}}{../lib/module-SimpleXMLRPCServer.html}
 | 
				
			||||||
  modules make implementing remote procedure calls into an almost trivial task.
 | 
					  modules make implementing remote procedure calls into an almost trivial task.
 | 
				
			||||||
  Despite the names, no direct knowledge or handling of XML is needed.
 | 
					  Despite the modules names, no direct knowledge or handling of XML is needed.
 | 
				
			||||||
\item The \ulink{\module{email}}{../lib/module-email.html} package is a library
 | 
					\item The \ulink{\module{email}}{../lib/module-email.html} package is a library
 | 
				
			||||||
  for managing email messages, including MIME and other RFC 2822-based message
 | 
					  for managing email messages, including MIME and other RFC 2822-based message
 | 
				
			||||||
  documents. Unlike \module{smptlib} and \module{poplib} which actually send
 | 
					  documents. Unlike \module{smptlib} and \module{poplib} which actually send
 | 
				
			||||||
| 
						 | 
					@ -4805,9 +4805,9 @@ programming needs.  These modules rarely occur in small scripts.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\section{Output Formatting\label{output-formatting}}
 | 
					\section{Output Formatting\label{output-formatting}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The \ulink{\module{repr}}{../lib/module-repr.html} module provides an
 | 
					The \ulink{\module{repr}}{../lib/module-repr.html} module provides a
 | 
				
			||||||
version of \function{repr()} for abbreviated displays of large or deeply
 | 
					version of \function{repr()} customized for abbreviated displays of large
 | 
				
			||||||
nested containers:
 | 
					or deeply nested containers:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
\begin{verbatim}
 | 
					\begin{verbatim}
 | 
				
			||||||
    >>> import repr   
 | 
					    >>> import repr   
 | 
				
			||||||
| 
						 | 
					@ -5097,7 +5097,7 @@ with different performance trade-offs.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The \ulink{\module{array}}{../lib/module-array.html} module provides an
 | 
					The \ulink{\module{array}}{../lib/module-array.html} module provides an
 | 
				
			||||||
\class{array()} object that is like a list that stores only homogenous
 | 
					\class{array()} object that is like a list that stores only homogenous
 | 
				
			||||||
data but stores it more compactly.  The following example shows an array
 | 
					data and stores it more compactly.  The following example shows an array
 | 
				
			||||||
of numbers stored as two byte unsigned binary numbers (typecode
 | 
					of numbers stored as two byte unsigned binary numbers (typecode
 | 
				
			||||||
\code{"H"}) rather than the usual 16 bytes per entry for regular lists
 | 
					\code{"H"}) rather than the usual 16 bytes per entry for regular lists
 | 
				
			||||||
of python int objects:
 | 
					of python int objects:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										144
									
								
								Lib/whrandom.py
									
										
									
									
									
								
							
							
						
						
									
										144
									
								
								Lib/whrandom.py
									
										
									
									
									
								
							| 
						 | 
					@ -1,144 +0,0 @@
 | 
				
			||||||
"""Wichman-Hill random number generator.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Wichmann, B. A. & Hill, I. D. (1982)
 | 
					 | 
				
			||||||
Algorithm AS 183:
 | 
					 | 
				
			||||||
An efficient and portable pseudo-random number generator
 | 
					 | 
				
			||||||
Applied Statistics 31 (1982) 188-190
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
see also:
 | 
					 | 
				
			||||||
        Correction to Algorithm AS 183
 | 
					 | 
				
			||||||
        Applied Statistics 33 (1984) 123
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        McLeod, A. I. (1985)
 | 
					 | 
				
			||||||
        A remark on Algorithm AS 183
 | 
					 | 
				
			||||||
        Applied Statistics 34 (1985),198-200
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
USE:
 | 
					 | 
				
			||||||
whrandom.random()       yields double precision random numbers
 | 
					 | 
				
			||||||
                        uniformly distributed between 0 and 1.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
whrandom.seed(x, y, z)  must be called before whrandom.random()
 | 
					 | 
				
			||||||
                        to seed the generator
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
There is also an interface to create multiple independent
 | 
					 | 
				
			||||||
random generators, and to choose from other ranges.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Multi-threading note: the random number generator used here is not
 | 
					 | 
				
			||||||
thread-safe; it is possible that nearly simultaneous calls in
 | 
					 | 
				
			||||||
different theads return the same random value.  To avoid this, you
 | 
					 | 
				
			||||||
have to use a lock around all calls.  (I didn't want to slow this
 | 
					 | 
				
			||||||
down in the serial case by using a lock here.)
 | 
					 | 
				
			||||||
"""
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import warnings
 | 
					 | 
				
			||||||
warnings.warn("the whrandom module is deprecated; please use the random module",
 | 
					 | 
				
			||||||
              DeprecationWarning)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Translated by Guido van Rossum from C source provided by
 | 
					 | 
				
			||||||
# Adrian Baddeley.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class whrandom:
 | 
					 | 
				
			||||||
    def __init__(self, x = 0, y = 0, z = 0):
 | 
					 | 
				
			||||||
        """Initialize an instance.
 | 
					 | 
				
			||||||
        Without arguments, initialize from current time.
 | 
					 | 
				
			||||||
        With arguments (x, y, z), initialize from them."""
 | 
					 | 
				
			||||||
        self.seed(x, y, z)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def seed(self, x = 0, y = 0, z = 0):
 | 
					 | 
				
			||||||
        """Set the seed from (x, y, z).
 | 
					 | 
				
			||||||
        These must be integers in the range [0, 256)."""
 | 
					 | 
				
			||||||
        if not type(x) == type(y) == type(z) == type(0):
 | 
					 | 
				
			||||||
            raise TypeError, 'seeds must be integers'
 | 
					 | 
				
			||||||
        if not (0 <= x < 256 and 0 <= y < 256 and 0 <= z < 256):
 | 
					 | 
				
			||||||
            raise ValueError, 'seeds must be in range(0, 256)'
 | 
					 | 
				
			||||||
        if 0 == x == y == z:
 | 
					 | 
				
			||||||
            # Initialize from current time
 | 
					 | 
				
			||||||
            import time
 | 
					 | 
				
			||||||
            t = long(time.time() * 256)
 | 
					 | 
				
			||||||
            t = int((t&0xffffff) ^ (t>>24))
 | 
					 | 
				
			||||||
            t, x = divmod(t, 256)
 | 
					 | 
				
			||||||
            t, y = divmod(t, 256)
 | 
					 | 
				
			||||||
            t, z = divmod(t, 256)
 | 
					 | 
				
			||||||
        # Zero is a poor seed, so substitute 1
 | 
					 | 
				
			||||||
        self._seed = (x or 1, y or 1, z or 1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def random(self):
 | 
					 | 
				
			||||||
        """Get the next random number in the range [0.0, 1.0)."""
 | 
					 | 
				
			||||||
        # This part is thread-unsafe:
 | 
					 | 
				
			||||||
        # BEGIN CRITICAL SECTION
 | 
					 | 
				
			||||||
        x, y, z = self._seed
 | 
					 | 
				
			||||||
        #
 | 
					 | 
				
			||||||
        x = (171 * x) % 30269
 | 
					 | 
				
			||||||
        y = (172 * y) % 30307
 | 
					 | 
				
			||||||
        z = (170 * z) % 30323
 | 
					 | 
				
			||||||
        #
 | 
					 | 
				
			||||||
        self._seed = x, y, z
 | 
					 | 
				
			||||||
        # END CRITICAL SECTION
 | 
					 | 
				
			||||||
        #
 | 
					 | 
				
			||||||
        return (x/30269.0 + y/30307.0 + z/30323.0) % 1.0
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def uniform(self, a, b):
 | 
					 | 
				
			||||||
        """Get a random number in the range [a, b)."""
 | 
					 | 
				
			||||||
        return a + (b-a) * self.random()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def randint(self, a, b):
 | 
					 | 
				
			||||||
        """Get a random integer in the range [a, b] including
 | 
					 | 
				
			||||||
        both end points.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        (Deprecated; use randrange below.)"""
 | 
					 | 
				
			||||||
        return self.randrange(a, b+1)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def choice(self, seq):
 | 
					 | 
				
			||||||
        """Choose a random element from a non-empty sequence."""
 | 
					 | 
				
			||||||
        return seq[int(self.random() * len(seq))]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def randrange(self, start, stop=None, step=1, int=int, default=None):
 | 
					 | 
				
			||||||
        """Choose a random item from range(start, stop[, step]).
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        This fixes the problem with randint() which includes the
 | 
					 | 
				
			||||||
        endpoint; in Python this is usually not what you want.
 | 
					 | 
				
			||||||
        Do not supply the 'int' and 'default' arguments."""
 | 
					 | 
				
			||||||
        # This code is a bit messy to make it fast for the
 | 
					 | 
				
			||||||
        # common case while still doing adequate error checking
 | 
					 | 
				
			||||||
        istart = int(start)
 | 
					 | 
				
			||||||
        if istart != start:
 | 
					 | 
				
			||||||
            raise ValueError, "non-integer arg 1 for randrange()"
 | 
					 | 
				
			||||||
        if stop is default:
 | 
					 | 
				
			||||||
            if istart > 0:
 | 
					 | 
				
			||||||
                return int(self.random() * istart)
 | 
					 | 
				
			||||||
            raise ValueError, "empty range for randrange()"
 | 
					 | 
				
			||||||
        istop = int(stop)
 | 
					 | 
				
			||||||
        if istop != stop:
 | 
					 | 
				
			||||||
            raise ValueError, "non-integer stop for randrange()"
 | 
					 | 
				
			||||||
        if step == 1:
 | 
					 | 
				
			||||||
            if istart < istop:
 | 
					 | 
				
			||||||
                return istart + int(self.random() *
 | 
					 | 
				
			||||||
                                   (istop - istart))
 | 
					 | 
				
			||||||
            raise ValueError, "empty range for randrange()"
 | 
					 | 
				
			||||||
        istep = int(step)
 | 
					 | 
				
			||||||
        if istep != step:
 | 
					 | 
				
			||||||
            raise ValueError, "non-integer step for randrange()"
 | 
					 | 
				
			||||||
        if istep > 0:
 | 
					 | 
				
			||||||
            n = (istop - istart + istep - 1) / istep
 | 
					 | 
				
			||||||
        elif istep < 0:
 | 
					 | 
				
			||||||
            n = (istop - istart + istep + 1) / istep
 | 
					 | 
				
			||||||
        else:
 | 
					 | 
				
			||||||
            raise ValueError, "zero step for randrange()"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if n <= 0:
 | 
					 | 
				
			||||||
            raise ValueError, "empty range for randrange()"
 | 
					 | 
				
			||||||
        return istart + istep*int(self.random() * n)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Initialize from the current time
 | 
					 | 
				
			||||||
_inst = whrandom()
 | 
					 | 
				
			||||||
seed = _inst.seed
 | 
					 | 
				
			||||||
random = _inst.random
 | 
					 | 
				
			||||||
uniform = _inst.uniform
 | 
					 | 
				
			||||||
randint = _inst.randint
 | 
					 | 
				
			||||||
choice = _inst.choice
 | 
					 | 
				
			||||||
randrange = _inst.randrange
 | 
					 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,8 @@ Extension Modules
 | 
				
			||||||
Library
 | 
					Library
 | 
				
			||||||
-------
 | 
					-------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- the deprecated whrandom module was removed.  Use the random module instead.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- heapq.nsmallest() and heapq.nlargest() now support key= arguments with
 | 
					- heapq.nsmallest() and heapq.nlargest() now support key= arguments with
 | 
				
			||||||
  the same meaning as in list.sort().
 | 
					  the same meaning as in list.sort().
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue