Skip to content

Commit b430399

Browse files
authored
GH-100234: Set a default value for random.expovariate() (GH-100235)
1 parent 8356c14 commit b430399

File tree

4 files changed

+8
-2
lines changed

4 files changed

+8
-2
lines changed

Doc/library/random.rst

+4-1
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,17 @@ be found in any statistics text.
320320
``beta > 0``. Returned values range between 0 and 1.
321321

322322

323-
.. function:: expovariate(lambd)
323+
.. function:: expovariate(lambd = 1.0)
324324

325325
Exponential distribution. *lambd* is 1.0 divided by the desired
326326
mean. It should be nonzero. (The parameter would be called
327327
"lambda", but that is a reserved word in Python.) Returned values
328328
range from 0 to positive infinity if *lambd* is positive, and from
329329
negative infinity to 0 if *lambd* is negative.
330330

331+
.. versionchanged:: 3.12
332+
Added the default value for ``lambd``.
333+
331334

332335
.. function:: gammavariate(alpha, beta)
333336

Lib/random.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def lognormvariate(self, mu, sigma):
577577
"""
578578
return _exp(self.normalvariate(mu, sigma))
579579

580-
def expovariate(self, lambd):
580+
def expovariate(self, lambd=1.0):
581581
"""Exponential distribution.
582582
583583
lambd is 1.0 divided by the desired mean. It should be

Lib/test/test_random.py

+1
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,7 @@ def test_zeroinputs(self):
988988
g.random = x[:].pop; g.uniform(1,10)
989989
g.random = x[:].pop; g.paretovariate(1.0)
990990
g.random = x[:].pop; g.expovariate(1.0)
991+
g.random = x[:].pop; g.expovariate()
991992
g.random = x[:].pop; g.weibullvariate(1.0, 1.0)
992993
g.random = x[:].pop; g.vonmisesvariate(1.0, 1.0)
993994
g.random = x[:].pop; g.normalvariate(0.0, 1.0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Set a default value of 1.0 for the ``lambd`` parameter in
2+
random.expovariate().

0 commit comments

Comments
 (0)