diff Lib/random.py @ 6698:b73eb4e6face legacy-trunk

Added Pareto and Weibull distributions, courtesy Jeremy Hylton.
author Guido van Rossum <guido@python.org>
date Tue, 02 Dec 1997 02:47:39 +0000
parents 7f891f32864c
children bca948194dea
line wrap: on
line diff
--- a/Lib/random.py	Tue Dec 02 00:30:04 1997 +0000
+++ b/Lib/random.py	Tue Dec 02 02:47:39 1997 +0000
@@ -212,6 +212,22 @@
 	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 @@
 	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