From: Raymond Hettinger Date: Sat, 25 Jun 2011 09:24:35 +0000 (+0200) Subject: Code simplification suggested by Sven Marnach. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cba87311d2dc395cbc56d00d7161d191ff7375d2;p=python Code simplification suggested by Sven Marnach. --- diff --git a/Lib/random.py b/Lib/random.py index 987cff16c4..36b956540b 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -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 --------------------