Skip to content

Commit e108916

Browse files
committed
gh-154001: Address review comments
1 parent e2560d6 commit e108916

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

Lib/random.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,11 @@ def binomialvariate(self, n=1, p=0.5):
861861
u = random()
862862
u -= 0.5
863863
us = 0.5 - _fabs(u)
864-
if us == 0.0:
864+
try:
865+
k = _floor((2.0 * a / us + b) * u + c)
866+
except ZeroDivisionError:
867+
# Reject case where random() returned 0.0
865868
continue
866-
k = _floor((2.0 * a / us + b) * u + c)
867869
if k < 0 or k > n:
868870
continue
869871
v = random()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Fix ``random.Random.binomialvariate()`` raising :exc:`ZeroDivisionError`
2-
when a random draw is zero.
1+
Fix :func:`random.binomialvariate` raising :exc:`ZeroDivisionError`
2+
when :func:`random.random` returns zero.

0 commit comments

Comments
 (0)