Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-100234: Set a default value for random.expovariate() #100235

Merged
merged 4 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Doc/library/random.rst
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,17 @@ 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
"lambda", but that is a reserved word in Python.) Returned values
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)

Expand Down
2 changes: 1 addition & 1 deletion Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def lognormvariate(self, mu, sigma):
"""
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
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,7 @@ def test_zeroinputs(self):
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Set a default value of 1.0 for the ``lambd`` parameter in
random.expovariate().