]> granicus.if.org Git - python/commitdiff
Code simplification suggested by Sven Marnach.
authorRaymond Hettinger <python@rcn.com>
Sat, 25 Jun 2011 09:30:53 +0000 (11:30 +0200)
committerRaymond Hettinger <python@rcn.com>
Sat, 25 Jun 2011 09:30:53 +0000 (11:30 +0200)
Lib/random.py

index 59a40526f8a5f116c74979e8b69a0269c306e073..ccc304dd66d75a932f8da6e3b792d4cfbad43586 100644 (file)
@@ -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 --------------------