Skip to content

Commit d9b69a5

Browse files
committed
gh-149221: Handle corner case in binomialvariate
1 parent bb5e41e commit d9b69a5

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Lib/random.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,11 @@ def binomialvariate(self, n=1, p=0.5):
836836
if not c:
837837
return x
838838
while True:
839-
y += _floor(_log2(random()) / c) + 1
839+
try:
840+
y += _floor(_log2(random()) / c) + 1
841+
except ValueError:
842+
# Handle rare case of where random() gives 0.0
843+
continue
840844
if y > n:
841845
return x
842846
x += 1

0 commit comments

Comments
 (0)