[Python-checkins] bpo-46737: Add default arguments to random.gauss and normalvariate (GH-31360)
rhettinger
webhook-mailer at python.org
Tue Feb 15 18:12:21 EST 2022
https://github.com/python/cpython/commit/08ec80113b3b7f7a9eaa3d217494536b63305181
commit: 08ec80113b3b7f7a9eaa3d217494536b63305181
branch: main
author: Zackery Spytz <zspytz at gmail.com>
committer: rhettinger <rhettinger at users.noreply.github.com>
date: 2022-02-15T17:12:15-06:00
summary:
bpo-46737: Add default arguments to random.gauss and normalvariate (GH-31360)
files:
A Misc/NEWS.d/next/Library/2022-02-15-07-39-43.bpo-46737.6Pnblt.rst
M Doc/library/random.rst
M Lib/random.py
M Lib/test/test_random.py
diff --git a/Doc/library/random.rst b/Doc/library/random.rst
index da4a4f61e4567..96c6300ea16f5 100644
--- a/Doc/library/random.rst
+++ b/Doc/library/random.rst
@@ -320,7 +320,7 @@ be found in any statistics text.
math.gamma(alpha) * beta ** alpha
-.. function:: gauss(mu, sigma)
+.. function:: gauss(mu=0.0, sigma=1.0)
Normal distribution, also called the Gaussian distribution. *mu* is the mean,
and *sigma* is the standard deviation. This is slightly faster than
@@ -333,6 +333,9 @@ be found in any statistics text.
number generator. 2) Put locks around all calls. 3) Use the
slower, but thread-safe :func:`normalvariate` function instead.
+ .. versionchanged:: 3.11
+ *mu* and *sigma* now have default arguments.
+
.. function:: lognormvariate(mu, sigma)
@@ -342,10 +345,13 @@ be found in any statistics text.
zero.
-.. function:: normalvariate(mu, sigma)
+.. function:: normalvariate(mu=0.0, sigma=1.0)
Normal distribution. *mu* is the mean, and *sigma* is the standard deviation.
+ .. versionchanged:: 3.11
+ *mu* and *sigma* now have default arguments.
+
.. function:: vonmisesvariate(mu, kappa)
diff --git a/Lib/random.py b/Lib/random.py
index 6d7b617e33a30..1f3530e880fce 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -538,7 +538,7 @@ def triangular(self, low=0.0, high=1.0, mode=None):
low, high = high, low
return low + (high - low) * _sqrt(u * c)
- def normalvariate(self, mu, sigma):
+ def normalvariate(self, mu=0.0, sigma=1.0):
"""Normal distribution.
mu is the mean, and sigma is the standard deviation.
@@ -559,7 +559,7 @@ def normalvariate(self, mu, sigma):
break
return mu + z * sigma
- def gauss(self, mu, sigma):
+ def gauss(self, mu=0.0, sigma=1.0):
"""Gaussian distribution.
mu is the mean, and sigma is the standard deviation. This is
diff --git a/Lib/test/test_random.py b/Lib/test/test_random.py
index 5b066d23dd3fd..32e7868ba4de7 100644
--- a/Lib/test/test_random.py
+++ b/Lib/test/test_random.py
@@ -409,6 +409,10 @@ def test_randbytes(self):
self.assertRaises(ValueError, self.gen.randbytes, -1)
self.assertRaises(TypeError, self.gen.randbytes, 1.0)
+ def test_mu_sigma_default_args(self):
+ self.assertIsInstance(self.gen.normalvariate(), float)
+ self.assertIsInstance(self.gen.gauss(), float)
+
try:
random.SystemRandom().random()
diff --git a/Misc/NEWS.d/next/Library/2022-02-15-07-39-43.bpo-46737.6Pnblt.rst b/Misc/NEWS.d/next/Library/2022-02-15-07-39-43.bpo-46737.6Pnblt.rst
new file mode 100644
index 0000000000000..c3f693aeb759e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-02-15-07-39-43.bpo-46737.6Pnblt.rst
@@ -0,0 +1,2 @@
+:func:`random.gauss` and :func:`random.normalvariate` now have default
+arguments.
More information about the Python-checkins
mailing list