diff options
author | Raymond Hettinger <python@rcn.com> | 2011-06-25 09:31:46 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2011-06-25 09:31:46 (GMT) |
commit | 12fb2f41f06e2ef084fffb23688ba21e52e3e012 (patch) | |
tree | 804a3d26e7330d6213bcac8d04a95d2407599fc5 /Lib/random.py | |
parent | 1db37f3248697d0a6fa24cea6b7112651f0e4abb (diff) | |
parent | 5279fb99cb309b422c2ba11eadc01368b6d997f1 (diff) | |
download | cpython-12fb2f41f06e2ef084fffb23688ba21e52e3e012.zip cpython-12fb2f41f06e2ef084fffb23688ba21e52e3e012.tar.gz cpython-12fb2f41f06e2ef084fffb23688ba21e52e3e012.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 49b7c93..a8f1a43 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 -------------------- |