Skip to content

Commit 206b82a

Browse files
Apply suggestion from @ByteFlowing1337
Co-authored-by: ByteFlow <fakeshadow1337@gmail.com>
1 parent e315b38 commit 206b82a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

Lib/random.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -838,12 +838,13 @@ def binomialvariate(self, n=1, p=0.5):
838838
while True:
839839
try:
840840
y += _floor(_log2(random()) / c) + 1
841+
# The random() function can return 0.0, which causes log2(0.0) to raise a ValueError.
842+
# See https://github.com/python/cpython/issue/149221
841843
except ValueError:
842-
# fix random() rethrn 0.0 option
843844
continue
844-
if y > n:
845-
return x
846-
x += 1
845+
if y > n:
846+
return x
847+
x += 1
847848

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

0 commit comments

Comments
 (0)