Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4695709

Browse filesBrowse files
authored
Move binomialvariate() to a section for discrete distributions (GH-102955)
1 parent f13fdac commit 4695709
Copy full SHA for 4695709

File tree

Expand file treeCollapse file tree

2 files changed

+28
-23
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-23
lines changed

‎Doc/library/random.rst

Copy file name to clipboardExpand all lines: Doc/library/random.rst
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,8 @@ Alternative Generator
404404
Class that implements the default pseudo-random number generator used by the
405405
:mod:`random` module.
406406

407-
.. deprecated:: 3.9
408-
In the future, the *seed* must be one of the following types:
407+
.. deprecated-removed:: 3.9 3.11
408+
Formerly the *seed* could be any hashable object. Now it is limited to:
409409
:class:`NoneType`, :class:`int`, :class:`float`, :class:`str`,
410410
:class:`bytes`, or :class:`bytearray`.
411411

@@ -423,7 +423,7 @@ Notes on Reproducibility
423423
------------------------
424424

425425
Sometimes it is useful to be able to reproduce the sequences given by a
426-
pseudo-random number generator. By re-using a seed value, the same sequence should be
426+
pseudo-random number generator. By reusing a seed value, the same sequence should be
427427
reproducible from run to run as long as multiple threads are not running.
428428

429429
Most of the random module's algorithms and seeding functions are subject to

‎Lib/random.py

Copy file name to clipboardExpand all lines: Lib/random.py
+25-20Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
negative exponential
2525
gamma
2626
beta
27-
binomial
2827
pareto
2928
Weibull
3029
@@ -33,6 +32,11 @@
3332
circular uniform
3433
von Mises
3534
35+
discrete distributions
36+
----------------------
37+
binomial
38+
39+
3640
General notes on the underlying Mersenne Twister core generator:
3741
3842
* The period is 2**19937-1.
@@ -731,6 +735,26 @@ def betavariate(self, alpha, beta):
731735
return y / (y + self.gammavariate(beta, 1.0))
732736
return 0.0
733737

738+
def paretovariate(self, alpha):
739+
"""Pareto distribution. alpha is the shape parameter."""
740+
# Jain, pg. 495
741+
742+
u = 1.0 - self.random()
743+
return u ** (-1.0 / alpha)
744+
745+
def weibullvariate(self, alpha, beta):
746+
"""Weibull distribution.
747+
748+
alpha is the scale parameter and beta is the shape parameter.
749+
750+
"""
751+
# Jain, pg. 499; bug fix courtesy Bill Arms
752+
753+
u = 1.0 - self.random()
754+
return alpha * (-_log(u)) ** (1.0 / beta)
755+
756+
757+
## -------------------- discrete distributions ---------------------
734758

735759
def binomialvariate(self, n=1, p=0.5):
736760
"""Binomial random variable.
@@ -816,25 +840,6 @@ def binomialvariate(self, n=1, p=0.5):
816840
return k
817841

818842

819-
def paretovariate(self, alpha):
820-
"""Pareto distribution. alpha is the shape parameter."""
821-
# Jain, pg. 495
822-
823-
u = 1.0 - self.random()
824-
return u ** (-1.0 / alpha)
825-
826-
def weibullvariate(self, alpha, beta):
827-
"""Weibull distribution.
828-
829-
alpha is the scale parameter and beta is the shape parameter.
830-
831-
"""
832-
# Jain, pg. 499; bug fix courtesy Bill Arms
833-
834-
u = 1.0 - self.random()
835-
return alpha * (-_log(u)) ** (1.0 / beta)
836-
837-
838843
## ------------------------------------------------------------------
839844
## --------------- Operating System Random Source ------------------
840845

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.