Skip to content

gh-154001: Avoid division by zero in binomialvariate#154004

Merged
serhiy-storchaka merged 4 commits into
python:mainfrom
lkk7:fix-binomialvariate-div-by-zero
Jul 19, 2026
Merged

gh-154001: Avoid division by zero in binomialvariate#154004
serhiy-storchaka merged 4 commits into
python:mainfrom
lkk7:fix-binomialvariate-div-by-zero

Conversation

@lkk7

@lkk7 lkk7 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

random.binomialvariate() can raise ZeroDivisionError when random() returns 0.0 in one of the paths.

My initial simplest proposal of the fix is to reject zero, matching the retry behavior used in the other path.

Added regression tests.

Fixes #154001

Comment thread Lib/random.py Outdated
Comment thread Misc/NEWS.d/next/Library/2026-07-18-17-09-49.gh-issue-154001.3brrUv.rst Outdated

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vstinner vstinner added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 18, 2026

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka
serhiy-storchaka merged commit 1f13740 into python:main Jul 19, 2026
51 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @lkk7 for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jul 19, 2026

Copy link
Copy Markdown

GH-154050 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 19, 2026
@bedevere-app

bedevere-app Bot commented Jul 19, 2026

Copy link
Copy Markdown

GH-154051 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 19, 2026
@bedevere-app

bedevere-app Bot commented Jul 19, 2026

Copy link
Copy Markdown

GH-154052 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 19, 2026
serhiy-storchaka pushed a commit that referenced this pull request Jul 19, 2026
… (GH-154052)

(cherry picked from commit 1f13740)

Co-authored-by: Łukasz <lukaszlapinski7@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request Jul 19, 2026
… (GH-154051)

(cherry picked from commit 1f13740)

Co-authored-by: Łukasz <lukaszlapinski7@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request Jul 19, 2026
… (GH-154050)

(cherry picked from commit 1f13740)

Co-authored-by: Łukasz <lukaszlapinski7@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

random.binomialvariate() can raise ZeroDivisionError when random() returns 0.0

4 participants