[Python-checkins] cpython (3.2): Code simplification suggested by Sven Marnach.
raymond.hettinger
python-checkins at python.org
Sat Jun 25 11:32:02 CEST 2011
http://hg.python.org/cpython/rev/9216e0a5d950
changeset: 70949:9216e0a5d950
branch: 3.2
parent: 70945:567236a7122c
user: Raymond Hettinger <python at rcn.com>
date: Sat Jun 25 11:30:53 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
@@ -402,11 +402,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