8000 Add extra tests for `random.binomialvariate` by gaogaotiantian · Pull Request #112325 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Add extra tests for random.binomialvariate #112325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 23, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revert changes to binomial variate
  • Loading branch information
gaogaotiantian committed Nov 23, 2023
commit 00cb3ea4191125ca90d761f726b97d07b4274753
6 changes: 1 addition & 5 deletions Lib/random.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,6 @@ def binomialvariate(self, n=1, p=0.5):

"""
# Error check inputs and handle edge cases
if not isinstance(n, int):
raise TypeError("n must be an integer")
if n < 0:
raise ValueError("n must be non-negative")
if p <= 0.0 or p >= 1.0:
Expand All @@ -815,8 +813,6 @@ def binomialvariate(self, n=1, p=0.5):
random = self.random

# Fast path for a common case
if n == 0:
return 0
if n == 1:
return _index(random() < p)

Expand All @@ -829,7 +825,7 @@ def binomialvariate(self, n=1, p=0.5):
# https://dl.acm.org/doi/pdf/10.1145/42372.42381
x = y = 0
c = _log2(1.0 - p)
if c == 0:
if not c:
return x
while True:
y += _floor(_log2(random()) / c) + 1
Expand Down
0