mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
Move binomialvariate() to a section for discrete distributions (GH-102955)
This commit is contained in:
parent
f13fdacadf
commit
4695709143
2 changed files with 28 additions and 23 deletions
|
@ -24,7 +24,6 @@
|
|||
negative exponential
|
||||
gamma
|
||||
beta
|
||||
binomial
|
||||
pareto
|
||||
Weibull
|
||||
|
||||
|
@ -33,6 +32,11 @@
|
|||
circular uniform
|
||||
von Mises
|
||||
|
||||
discrete distributions
|
||||
----------------------
|
||||
binomial
|
||||
|
||||
|
||||
General notes on the underlying Mersenne Twister core generator:
|
||||
|
||||
* The period is 2**19937-1.
|
||||
|
@ -731,6 +735,26 @@ class Random(_random.Random):
|
|||
return y / (y + self.gammavariate(beta, 1.0))
|
||||
return 0.0
|
||||
|
||||
def paretovariate(self, alpha):
|
||||
"""Pareto distribution. alpha is the shape parameter."""
|
||||
# Jain, pg. 495
|
||||
|
||||
u = 1.0 - self.random()
|
||||
return u ** (-1.0 / alpha)
|
||||
|
||||
def weibullvariate(self, alpha, beta):
|
||||
"""Weibull distribution.
|
||||
|
||||
alpha is the scale parameter and beta is the shape parameter.
|
||||
|
||||
"""
|
||||
# Jain, pg. 499; bug fix courtesy Bill Arms
|
||||
|
||||
u = 1.0 - self.random()
|
||||
return alpha * (-_log(u)) ** (1.0 / beta)
|
||||
|
||||
|
||||
## -------------------- discrete distributions ---------------------
|
||||
|
||||
def binomialvariate(self, n=1, p=0.5):
|
||||
"""Binomial random variable.
|
||||
|
@ -816,25 +840,6 @@ class Random(_random.Random):
|
|||
return k
|
||||
|
||||
|
||||
def paretovariate(self, alpha):
|
||||
"""Pareto distribution. alpha is the shape parameter."""
|
||||
# Jain, pg. 495
|
||||
|
||||
u = 1.0 - self.random()
|
||||
return u ** (-1.0 / alpha)
|
||||
|
||||
def weibullvariate(self, alpha, beta):
|
||||
"""Weibull distribution.
|
||||
|
||||
alpha is the scale parameter and beta is the shape parameter.
|
||||
|
||||
"""
|
||||
# Jain, pg. 499; bug fix courtesy Bill Arms
|
||||
|
||||
u = 1.0 - self.random()
|
||||
return alpha * (-_log(u)) ** (1.0 / beta)
|
||||
|
||||
|
||||
## ------------------------------------------------------------------
|
||||
## --------------- Operating System Random Source ------------------
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue