René's URL Explorer Experiment


Title: random.choices produces strongly biased results for equal subnormal weights · Issue #158748 · python/cpython · GitHub

Open Graph Title: random.choices produces strongly biased results for equal subnormal weights · Issue #158748 · python/cpython

X Title: random.choices produces strongly biased results for equal subnormal weights · Issue #158748 · python/cpython

Description: Bug report Bug description: Documented behaviour: Python random documentation, choices(): “If a weights sequence is specified, selections are made according to the relative weights.” Equal relative weights imply equal selection probabili...

Open Graph Description: Bug report Bug description: Documented behaviour: Python random documentation, choices(): “If a weights sequence is specified, selections are made according to the relative weights.” Equal relative...

X Description: Bug report Bug description: Documented behaviour: Python random documentation, choices(): “If a weights sequence is specified, selections are made according to the relative weights.” Equal relative...

Opengraph URL: https://github.com/python/cpython/issues/158748

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"random.choices produces strongly biased results for equal subnormal weights","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\n**Documented behaviour:** Python random documentation, choices(): “If a weights sequence is specified, selections are made according to the relative weights.” Equal relative weights imply equal selection probabilities.\r\n\r\n**Expected:** Equal selection probabilities, with approximately 50000 selections per element; scaling to [1.0, 1.0] should preserve the distribution.\r\n\r\n**Actual:** 25146 selections of 'a' and 74854 of 'b', consistent with probabilities approximately 1/4 and 3/4.\r\n\r\n```python\r\nimport random, math\r\nfrom fractions import Fraction\r\n\r\np, w, k, seed = ['a', 'b'], [2**-1074]*2, 100000, 0\r\ndata = dict(population=p, weights=w, k=k, seed=seed)\r\nif not (len(p) == len(w) and all(math.isfinite(x) and x > 0 for x in w)\r\n        and math.isfinite(sum(w)) and sum(w) > 0):\r\n    print(\"REFUTATION REJECTED:\", \"invalid input\", data)\r\nelse:\r\n    q = [Fraction(x) for x in w]\r\n    probabilities = [x / sum(q) for x in q]\r\n    draws = random.Random(seed).choices(p, weights=w, k=k)\r\n    actual = {x: draws.count(x) for x in p}\r\n    expected = {x: dict(probability=str(t), mean=k*float(t),\r\n                       tolerance=10*math.sqrt(k*float(t)*(1-float(t))))\r\n                for x, t in zip(p, probabilities)}\r\n    broken = any(abs(actual[x] - expected[x]['mean']) > expected[x]['tolerance']\r\n                 for x in p)\r\n    if broken:\r\n        print(\"REFUTATION CONFIRMED:\", data, \"actual:\", actual, \"expected:\", expected)\r\n    else:\r\n        print(\"REFUTATION REJECTED:\", \"counts within 10 standard deviations\",\r\n              data, \"actual:\", actual, \"expected:\", expected)\r\n```\r\n\r\nOutput on Python 3.14.6 (Windows-11-10.0.26220-SP0), standard library `random`:\r\n\r\n```\r\nREFUTATION CONFIRMED: {'population': ['a', 'b'], 'weights': [5e-324, 5e-324], 'k': 100000, 'seed': 0} actual: {'a': 25146, 'b': 74854} expected: {'a': {'probability': '1/2', 'mean': 50000.0, 'tolerance': 1581.1388300841897}, 'b': {'probability': '1/2', 'mean': 50000.0, 'tolerance': 1581.1388300841897}}\r\n```\r\n\r\nThis report was found and written by an automated property-testing tool I run ([bugforge](https://github.com/augusto-rehfeldt/bugforge)). The reproducer above was executed and its output is pasted unedited; no person reviewed the report before it was filed. The search script is in https://github.com/augusto-rehfeldt/bugforge-results/tree/main/random-20261003-202849-c3\r\n\r\n### CPython versions tested on:\r\n\r\n3.14\r\n\r\n### Operating systems tested on:\r\n\r\nWindows\r\n","author":{"url":"https://github.com/augusto-rehfeldt","@type":"Person","name":"augusto-rehfeldt"},"datePublished":"2026-10-04T01:04:33Z","url":"https://github.com/python/cpython/issues/158748"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:7b51fc47-f74d-9c6b-737a-9f2abc51c993
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8E52:34CAB:40827A9:5267FEE:6B022F57
html-safe-nonce1ea81a921b3e67c1b1f6d3b7eede15cddbed4921e84447660befab07dcd475f7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTUyOjM0Q0FCOjQwODI3QTk6NTI2N0ZFRTo2QjAyMkY1NyIsInZpc2l0b3JfaWQiOiIyMzA5NDE1NzI4MDE0NTY5MzAzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacc792593eaa73590cb24fe753488ba6fb67791a31687561bdb7da7f181e56302f
hovercard-subject-tagissue:5695093120
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/158748/issue_layout
twitter:imagehttps://opengraph.githubassets.com/f3024940d8764536a95e696105b3ea8fe96e6830f49663dac64904979bc47970/python/cpython/issues/158748
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/f3024940d8764536a95e696105b3ea8fe96e6830f49663dac64904979bc47970/python/cpython/issues/158748
og:image:altBug report Bug description: Documented behaviour: Python random documentation, choices(): “If a weights sequence is specified, selections are made according to the relative weights.” Equal relative...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameaugusto-rehfeldt
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/158748#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F158748
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F158748
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/158748
Reloadhttps://github.com/python/cpython/issues/158748
Reloadhttps://github.com/python/cpython/issues/158748
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/158748
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/158748
random.choices produces strongly biased results for equal subnormal weightshttps://github.com/python/cpython/issues/158748#top
https://github.com/augusto-rehfeldt
augusto-rehfeldthttps://github.com/augusto-rehfeldt
on Oct 4, 2026https://github.com/python/cpython/issues/158748#issue-5695093120
bugforgehttps://github.com/augusto-rehfeldt/bugforge
https://github.com/augusto-rehfeldt/bugforge-results/tree/main/random-20261003-202849-c3https://github.com/augusto-rehfeldt/bugforge-results/tree/main/random-20261003-202849-c3
augusto-rehfeldthttps://github.com/augusto-rehfeldt
on Oct 4, 2026https://github.com/python/cpython/issues/158748#event-32422605746
Link random-20261003-202849-c3 to python/cpython#158748https://github.com/augusto-rehfeldt/bugforge-results/commit/4118e18c8ebba32901e5f3ab1c3390f978524c4d
python/cpython#158748https://github.com/python/cpython/issues/158748
4118e18https://github.com/augusto-rehfeldt/bugforge-results/commit/4118e18c8ebba32901e5f3ab1c3390f978524c4d
https://github.com/ZeroIntensity
ZeroIntensityhttps://github.com/ZeroIntensity
on Oct 4, 2026https://github.com/python/cpython/issues/158748#issuecomment-5975238560
ZeroIntensityhttps://github.com/ZeroIntensity
not plannedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Oct 4, 2026https://github.com/python/cpython/issues/158748#event-32422626506
https://github.com/augusto-rehfeldt
augusto-rehfeldthttps://github.com/augusto-rehfeldt
on Oct 4, 2026https://github.com/python/cpython/issues/158748#issuecomment-5975435941
#158786https://github.com/python/cpython/issues/158786
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/158748
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/158748
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.