Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 12fb2f4

Browse files
committed
Code simplification suggested by Sven Marnach.
2 parents 1db37f3 + 5279fb9 commit 12fb2f4

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

Lib/random.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,9 @@ def expovariate(self, lambd):
402402
# lambd: rate lambd = 1/mean
403403
# ('lambda' is a Python reserved word)
404404

405-
random = self.random
406-
u = random()
407-
while u <= 1e-7:
408-
u = random()
409-
return -_log(u)/lambd
405+
# we use 1-random() instead of random() to preclude the
406+
# possibility of taking the log of zero.
407+
return -_log(1.0 - self.random())/lambd
410408

411409
## -------------------- von Mises distribution --------------------
412410

0 commit comments

Comments
 (0)