[Python-checkins] cpython (2.7): Code simplification suggested by Sven Marnach.
raymond.hettinger
python-checkins at python.org
Sat Jun 25 11:24:46 CEST 2011
http://hg.python.org/cpython/rev/4970fa3c4a0b
changeset: 70948:4970fa3c4a0b
branch: 2.7
user: Raymond Hettinger <python at rcn.com>
date: Sat Jun 25 11:24:35 2011 +0200
summary:
Code simplification suggested by Sven Marnach.
files:
Lib/random.py | 8 +++-----
1 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/Lib/random.py b/Lib/random.py
--- a/Lib/random.py
+++ b/Lib/random.py
@@ -427,11 +427,9 @@
# 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 --------------------
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list