[Python-checkins] Move binomialvariate() to a section for discrete distributions (GH-102955)

rhettinger webhook-mailer at python.org
Thu Mar 23 13:10:20 EDT 2023


https://github.com/python/cpython/commit/46957091433bfa097d7ea19b177bf42a52412f2d
commit: 46957091433bfa097d7ea19b177bf42a52412f2d
branch: main
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2023-03-23T12:10:12-05:00
summary:

Move binomialvariate() to a section for discrete distributions (GH-102955)

files:
M Doc/library/random.rst
M Lib/random.py

diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index 098684d7270f..c192919ac62e 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -404,8 +404,8 @@ Alternative Generator
    Class that implements the default pseudo-random number generator used by the
    :mod:`random` module.
 
-   .. deprecated:: 3.9
-      In the future, the *seed* must be one of the following types:
+   .. deprecated-removed:: 3.9 3.11
+      Formerly the *seed* could be any hashable object.  Now it is limited to:
       :class:`NoneType`, :class:`int`, :class:`float`, :class:`str`,
       :class:`bytes`, or :class:`bytearray`.
 
@@ -423,7 +423,7 @@ Notes on Reproducibility
 ------------------------
 
 Sometimes it is useful to be able to reproduce the sequences given by a
-pseudo-random number generator.  By re-using a seed value, the same sequence should be
+pseudo-random number generator.  By reusing a seed value, the same sequence should be
 reproducible from run to run as long as multiple threads are not running.
 
 Most of the random module's algorithms and seeding functions are subject to
diff --git a/Lib/random.py b/Lib/random.py
index 3c4291f6a652..586c3f7f9da9 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -24,7 +24,6 @@
            negative exponential
            gamma
            beta
-           binomial
            pareto
            Weibull
 
@@ -33,6 +32,11 @@
            circular uniform
            von Mises
 
+    discrete distributions
+    ----------------------
+           binomial
+
+
 General notes on the underlying Mersenne Twister core generator:
 
 * The period is 2**19937-1.
@@ -731,6 +735,26 @@ def betavariate(self, alpha, beta):
             return y / (y + self.gammavariate(beta, 1.0))
         return 0.0
 
+    def paretovariate(self, alpha):
+        """Pareto distribution.  alpha is the shape parameter."""
+        # Jain, pg. 495
+
+        u = 1.0 - self.random()
+        return u ** (-1.0 / alpha)
+
+    def weibullvariate(self, alpha, beta):
+        """Weibull distribution.
+
+        alpha is the scale parameter and beta is the shape parameter.
+
+        """
+        # Jain, pg. 499; bug fix courtesy Bill Arms
+
+        u = 1.0 - self.random()
+        return alpha * (-_log(u)) ** (1.0 / beta)
+
+
+    ## -------------------- discrete  distributions  ---------------------
 
     def binomialvariate(self, n=1, p=0.5):
         """Binomial random variable.
@@ -816,25 +840,6 @@ def binomialvariate(self, n=1, p=0.5):
                 return k
 
 
-    def paretovariate(self, alpha):
-        """Pareto distribution.  alpha is the shape parameter."""
-        # Jain, pg. 495
-
-        u = 1.0 - self.random()
-        return u ** (-1.0 / alpha)
-
-    def weibullvariate(self, alpha, beta):
-        """Weibull distribution.
-
-        alpha is the scale parameter and beta is the shape parameter.
-
-        """
-        # Jain, pg. 499; bug fix courtesy Bill Arms
-
-        u = 1.0 - self.random()
-        return alpha * (-_log(u)) ** (1.0 / beta)
-
-
 ## ------------------------------------------------------------------
 ## --------------- Operating System Random Source  ------------------
 



More information about the Python-checkins mailing list