summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-12-02 02:47:39 (GMT)
committerGuido van Rossum <guido@python.org>1997-12-02 02:47:39 (GMT)
commitcf4559a62ec9316a3bb55a67c6fca81ec1ad0d18 (patch)
tree0eaae870304815719e40986151f33eee6989065c
parentc99a239f4277b76fcdcc85772847d07fa49cf10a (diff)
downloadcpython-cf4559a62ec9316a3bb55a67c6fca81ec1ad0d18.zip
cpython-cf4559a62ec9316a3bb55a67c6fca81ec1ad0d18.tar.gz
cpython-cf4559a62ec9316a3bb55a67c6fca81ec1ad0d18.tar.bz2
Added Pareto and Weibull distributions, courtesy Jeremy Hylton.
-rw-r--r--Lib/random.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 608203f..52a4266 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -212,6 +212,22 @@ def betavariate(alpha, beta):
z = expovariate(1.0/beta)
return z/(y+z)
+# -------------------- pareto --------------------
+
+def paretovariate(alpha):
+ # Jain, pg. 495
+
+ u = random()
+ return 1.0 / pow(u, 1.0/alpha)
+
+# -------------------- pareto --------------------
+
+def weibullvariate(alpha, beta):
+ # Jain, pg. 499; bug fix courtesy Bill Arms
+
+ u = random()
+ return alpha * pow(-log(u), 1.0/beta)
+
# -------------------- test program --------------------
def test(N = 200):
@@ -233,6 +249,8 @@ def test(N = 200):
test_generator(N, 'gammavariate(200.0, 1.0)')
test_generator(N, 'gauss(0.0, 1.0)')
test_generator(N, 'betavariate(3.0, 3.0)')
+ test_generator(N, 'paretovariate(1.0)')
+ test_generator(N, 'weibullvariate(1.0, 1.0)')
def test_generator(n, funccall):
import time