summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2022-12-15 18:40:45 (GMT)
committerGitHub <noreply@github.com>2022-12-15 18:40:45 (GMT)
commitb430399d41fa88e9040cd055e55cf9211bf63c61 (patch)
treea83f25c8bb342a19bbefe8f76208eff2c0f43fc1
parent8356c14b4f81f4d0010afb61610edacf4068b804 (diff)
downloadcpython-b430399d41fa88e9040cd055e55cf9211bf63c61.zip
cpython-b430399d41fa88e9040cd055e55cf9211bf63c61.tar.gz
cpython-b430399d41fa88e9040cd055e55cf9211bf63c61.tar.bz2
GH-100234: Set a default value for random.expovariate() (GH-100235)
-rw-r--r--Doc/library/random.rst5
-rw-r--r--Lib/random.py2
-rw-r--r--Lib/test/test_random.py1
-rw-r--r--Misc/NEWS.d/next/Library/2022-12-14-11-45-38.gh-issue-100234.kn6yWV.rst2
4 files changed, 8 insertions, 2 deletions
diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index 669204b..d944518 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -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)
diff --git a/Lib/random.py b/Lib/random.py
index c70294e..e60b729 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -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
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index 1e825c35..67de54c 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -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
index 0000000..6d9b909
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-12-14-11-45-38.gh-issue-100234.kn6yWV.rst
@@ -0,0 +1,2 @@
+Set a default value of 1.0 for the ``lambd`` parameter in
+random.expovariate().