From 387fb0cc96cbadbcf5a261553ec0a0ff38e0568c Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 14 Dec 2022 11:30:00 +0200 Subject: [PATCH 1/4] Set default lamb to one. --- Doc/library/random.rst | 5 ++++- Lib/random.py | 2 +- Lib/test/test_random.py | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Doc/library/random.rst b/Doc/library/random.rst index 669204ba65b77e..be5e995e7f0ce8 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 c70294ee0cbf08..e60b7294b6dd6a 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -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 diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py index 1e825c3572d20a..67de54c7db8b13 100644 --- a/Lib/test/test_random.py +++ b/Lib/test/test_random.py @@ -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) From b72f1c4b1ebee6ed72da4966c4574ac9e3cffcf6 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 14 Dec 2022 11:46:03 +0200 Subject: [PATCH 2/4] Add blurb --- .../next/Library/2022-12-14-11-45-38.gh-issue-100234.kn6yWV.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2022-12-14-11-45-38.gh-issue-100234.kn6yWV.rst 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 00000000000000..e8920afbf12558 --- /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(). From 017a7939ccee61a678b807a262a7dab6eb8de7ad Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 14 Dec 2022 12:09:24 +0200 Subject: [PATCH 3/4] Fix markup --- Doc/library/random.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/random.rst b/Doc/library/random.rst index be5e995e7f0ce8..d944518a7909bc 100644 --- a/Doc/library/random.rst +++ b/Doc/library/random.rst @@ -329,7 +329,7 @@ be found in any statistics text. negative infinity to 0 if *lambd* is negative. .. versionchanged:: 3.12 - Added the default value for `lambd`. + Added the default value for ``lambd``. .. function:: gammavariate(alpha, beta) From c49e1b7855e25b7b064e84da663f9023177e04df Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Wed, 14 Dec 2022 12:29:44 +0200 Subject: [PATCH 4/4] Fix markup --- .../next/Library/2022-12-14-11-45-38.gh-issue-100234.kn6yWV.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index e8920afbf12558..6d9b909d874b34 100644 --- 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 @@ -1,2 +1,2 @@ -Set a default value of 1.0 for the `lambd` parameter in +Set a default value of 1.0 for the ``lambd`` parameter in random.expovariate().