diff options
author | Raymond Hettinger <python@rcn.com> | 2011-06-25 09:30:53 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-06-25 09:30:53 (GMT) |
commit | 5279fb99cb309b422c2ba11eadc01368b6d997f1 (patch) | |
tree | 0747107609c9d562337803b863c0da0b225f6093 /Lib/random.py | |
parent | dbfb9b89db6cf2f1bc63c9be9bfab476d7141181 (diff) | |
download | cpython-5279fb99cb309b422c2ba11eadc01368b6d997f1.zip cpython-5279fb99cb309b422c2ba11eadc01368b6d997f1.tar.gz cpython-5279fb99cb309b422c2ba11eadc01368b6d997f1.tar.bz2 |
Code simplification suggested by Sven Marnach.
Diffstat (limited to 'Lib/random.py')
-rw-r--r-- | Lib/random.py | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/Lib/random.py b/Lib/random.py index 59a4052..ccc304d 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -402,11 +402,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 -------------------- |