Skip to content

Commit d036e89

Browse files
authored
Fix exception handling in random and reuse try-except loop
Handle ValueError in random number generation loop.
1 parent e73278a commit d036e89

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Lib/random.py

Lines changed: 4 additions & 0 deletions
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+
try:
839840
y += _floor(_log2(random()) / c) + 1
841+
except ValueError:
842+
# fix random() rethrn 0.0 option
843+
continue
840844
if y > n:
841845
return x
842846
x += 1

0 commit comments

Comments
 (0)