8000 bpo-46737: Add default arguments to random.{gauss,normalvariate} by ZackerySpytz · Pull Request #31360 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

bpo-46737: Add default arguments to random.{gauss,normalvariate} #31360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Doc/library/random.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

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

Expand Down
4 changes: 2 additions & 2 deletions Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8000 Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
< 7301 div class="file-header d-flex flex-md-row flex-column flex-md-items-center file-header--expandable js-file-header js-skip-tagsearch sticky-file-header" data-path="Misc/NEWS.d/next/Library/2022-02-15-07-39-43.bpo-46737.6Pnblt.rst" data-short-path="5dfdae6" data-anchor="diff-5dfdae67238dfe2451a0e9a51ccfa5002f63fcd447fb80423e02e0cf2cb5d7e1" data-file-type=".rst" data-file-deleted="false" >
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`random.gauss` and :func:`random.normalvariate` now have default
arguments.
0