Skip to content

Commit

Permalink
GH-100234: Set a default value for random.expovariate() (GH-100235)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger authored Dec 15, 2022
1 parent 8356c14 commit b430399
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
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().

0 comments on commit b430399

Please sign in to comment.