From: Raymond Hettinger Date: Sat, 25 Jun 2011 09:30:53 +0000 (+0200) Subject: Code simplification suggested by Sven Marnach. X-Git-Tag: v3.2.1rc2~59 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5279fb99cb309b422c2ba11eadc01368b6d997f1;p=thirdparty%2FPython%2Fcpython.git Code simplification suggested by Sven Marnach. --- diff --git a/Lib/random.py b/Lib/random.py index 59a40526f8a5..ccc304dd66d7 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 --------------------