Skip to content

Commit 1ca8d09

Browse files
authored
Fix handling of log(0) case in random.py
1 parent e7233dc commit 1ca8d09

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

Lib/random.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,12 +840,10 @@ def binomialvariate(self, n=1, p=0.5):
840840
y += _floor(_log2(random()) / c) + 1
841841
except ValueError:
842842
# Handle rare case of log(0.0)
843-
if c < 0:
844-
# When c < 0, log(0) mathematically gives +infinity, so y > n.
845-
y = n + 1
843+
continue
846844
if y > n:
847845
return x
848-
x += 1
846+
x += 1
849847

850848
# BTRS: Transformed rejection with squeeze method by Wolfgang Hörmann
851849
# https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.47.8407&rep=rep1&type=pdf

0 commit comments

Comments
 (0)