]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-100234: Set a default value for random.expovariate() (GH-100235)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Thu, 15 Dec 2022 18:40:45 +0000 (20:40 +0200)
committerGitHub <noreply@github.com>
Thu, 15 Dec 2022 18:40:45 +0000 (12:40 -0600)
Doc/library/random.rst
Lib/random.py
Lib/test/test_random.py
Misc/NEWS.d/next/Library/2022-12-14-11-45-38.gh-issue-100234.kn6yWV.rst [new file with mode: 0644]

index 669204ba65b77e17b32a33506439b7dbd504c34e..d944518a7909bc895f4f056a375ff31112cb7b92 100644 (file)
@@ -320,7 +320,7 @@ be found in any statistics text.
    ``beta > 0``. Returned values range between 0 and 1.
 
 
-.. function:: expovariate(lambd)
+.. function:: expovariate(lambd = 1.0)
 
    Exponential distribution.  *lambd* is 1.0 divided by the desired
    mean.  It should be nonzero.  (The parameter would be called
@@ -328,6 +328,9 @@ be found in any statistics text.
    range from 0 to positive infinity if *lambd* is positive, and from
    negative infinity to 0 if *lambd* is negative.
 
+   .. versionchanged:: 3.12
+      Added the default value for ``lambd``.
+
 
 .. function:: gammavariate(alpha, beta)
 
index c70294ee0cbf08cf4627e195cf7d049f9a6346dc..e60b7294b6dd6af5d8525b218879ea01574b943a 100644 (file)
@@ -577,7 +577,7 @@ class Random(_random.Random):
         """
         return _exp(self.normalvariate(mu, sigma))
 
-    def expovariate(self, lambd):
+    def expovariate(self, lambd=1.0):
         """Exponential distribution.
 
         lambd is 1.0 divided by the desired mean.  It should be
index 1e825c3572d20aa2e9d39ce967973d1a48ebbaed..67de54c7db8b13997bd25a7ded3be437fdf09976 100644 (file)
@@ -988,6 +988,7 @@ class TestDistributions(unittest.TestCase):
         g.random = x[:].pop; g.uniform(1,10)
         g.random = x[:].pop; g.paretovariate(1.0)
         g.random = x[:].pop; g.expovariate(1.0)
+        g.random = x[:].pop; g.expovariate()
         g.random = x[:].pop; g.weibullvariate(1.0, 1.0)
         g.random = x[:].pop; g.vonmisesvariate(1.0, 1.0)
         g.random = x[:].pop; g.normalvariate(0.0, 1.0)
diff --git a/Misc/NEWS.d/next/Library/2022-12-14-11-45-38.gh-issue-100234.kn6yWV.rst b/Misc/NEWS.d/next/Library/2022-12-14-11-45-38.gh-issue-100234.kn6yWV.rst
new file mode 100644 (file)
index 0000000..6d9b909
--- /dev/null
@@ -0,0 +1,2 @@
+Set a default value of 1.0 for the ``lambd`` parameter in
+random.expovariate().