8000 bpo-46737: Add default arguments to random.gauss and normalvariate (G… · python/cpython@08ec801 · GitHub
[go: up one dir, main page]

Skip to content

Commit 08ec801

Browse files
authored
bpo-46737: Add default arguments to random.gauss and normalvariate (GH-31360)
1 parent 1d81fdc commit 08ec801

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

Doc/library/random.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ be found in any statistics text.
320320
math.gamma(alpha) * beta ** alpha
321321

322322

323-
.. function:: gauss(mu, sigma)
323+
.. function:: gauss(mu=0.0, sigma=1.0)
324324

325325
Normal distribution, also called the Gaussian distribution. *mu* is the mean,
326326
and *sigma* is the standard deviation. This is slightly faster than
@@ -333,6 +333,9 @@ be found in any statistics text.
333333
number generator. 2) Put locks around all calls. 3) Use the
334334
slower, but thread-safe :func:`normalvariate` function instead.
335335

336+
.. versionchanged:: 3.11
337+
*mu* and *sigma* now have default arguments.
338+
336339

337340
.. function:: lognormvariate(mu, sigma)
338341

@@ -342,10 +345,13 @@ be found in any statistics text.
342345
zero.
343346

344347

345-
.. function:: normalvariate(mu, sigma)
348+
.. function:: normalvariate(mu=0.0, sigma=1.0)
346349

347350
Normal distribution. *mu* is the mean, and *sigma* is the standard deviation.
348351

352+
.. versionchanged:: 3.11
353+
*mu* and *sigma* now have default arguments.
354+
349355

350356
.. function:: vonmisesvariate(mu, kappa)
351357

Lib/random.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def triangular(self, low=0.0, high=1.0, mode=None):
538538
low, high = high, low
539539
return low + (high - low) * _sqrt(u * c)
540540

541-
def normalvariate(self, mu, sigma):
541+
def normalvariate(self, mu=0.0, sigma=1.0):
542542
"""Normal distribution.
543543
544544
mu is the mean, and sigma is the standard deviation.
@@ -559,7 +559,7 @@ def normalvariate(self, mu, sigma):
559559
break
560560
return mu + z * sigma
561561

562-
def gauss(self, mu, sigma):
562+
def gauss(self, mu=0.0, sigma=1.0):
563563
"""Gaussian distribution.
564564
565565
mu is the mean, and sigma is the standard deviation. This is

Lib/test/test_random.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ def test_randbytes(self):
409409
self.assertRaises(ValueError, self.gen.randbytes, -1)
410410
self.assertRaises(TypeError, self.gen.randbytes, 1.0)
411411

412+
def test_mu_sigma_default_args(self):
413+
self.assertIsInstance(self.gen.normalvariate(), float)
414+
self.assertIsInstance(self.gen.gauss(), float)
415+
412416

413417
try:
414418
random.SystemRandom().random()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:func:`random.gauss` and :func:`random.normalvariate` now have default
2+
arguments.

0 commit comments

Comments
 (0)
0