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

index 987cff16c4eef34f58ee2264a1769d3d2d34e173..36b956540bfeefe9b0402b1ce04ef194ee15585c 100644 (file)
@@ -427,11 +427,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 --------------------