summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-06-25 09:24:35 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-06-25 09:24:35 (GMT)
commitcba87311d2dc395cbc56d00d7161d191ff7375d2 (patch)
treeaa900d71c6f4789ee1052a3e464883cd42d82e7d /Lib
parentcb9bf1ac9c420249f9598931c777b9df83a8d22d (diff)
downloadcpython-cba87311d2dc395cbc56d00d7161d191ff7375d2.zip
cpython-cba87311d2dc395cbc56d00d7161d191ff7375d2.tar.gz
cpython-cba87311d2dc395cbc56d00d7161d191ff7375d2.tar.bz2
Code simplification suggested by Sven Marnach.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/random.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/Lib/random.py b/Lib/random.py
index 987cff1..36b9565 100644
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -427,11 +427,9 @@ class Random(_random.Random):
# lambd: rate lambd = 1/mean
# ('lambda' is a Python reserved word)
- random = self.random
- u = random()
- while u <= 1e-7:
- u = random()
- return -_log(u)/lambd
+ # we use 1-random() instead of random() to preclude the
+ # possibility of taking the log of zero.
+ return -_log(1.0 - self.random())/lambd
## -------------------- von Mises distribution --------------------