diff --git a/Lib/random.py b/Lib/random.py index c89cbb755abac8..2460ac3d98601f 100644 --- a/Lib/random.py +++ b/Lib/random.py @@ -836,7 +836,11 @@ def binomialvariate(self, n=1, p=0.5): if not c: return x while True: - y += _floor(_log2(random()) / c) + 1 + try: + y += _floor(_log2(random()) / c) + 1 + except ValueError: + # Handle rare case of where random() gives 0.0 + continue if y > n: return x x += 1