bpo-46737: Add default arguments to random.gauss and normalvariate (GH-31360)

This commit is contained in:
Zackery Spytz 2022-02-15 15:12:15 -08:00 committed by GitHub
parent 1d81fdc4c0
commit 08ec80113b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 4 deletions

View File

@ -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)

View File

@ -538,7 +538,7 @@ class Random(_random.Random):
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 @@ class Random(_random.Random):
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

View File

@ -409,6 +409,10 @@ class TestBasicOps:
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()

View File

@ -0,0 +1,2 @@
:func:`random.gauss` and :func:`random.normalvariate` now have default
arguments.