René's URL Explorer Experiment


Title: Fix random.randint() with negative numbers by greatsong · Pull Request #215 · vpython/glowscript · GitHub

Open Graph Title: Fix random.randint() with negative numbers by greatsong · Pull Request #215 · vpython/glowscript

X Title: Fix random.randint() with negative numbers by greatsong · Pull Request #215 · vpython/glowscript

Description: On glowscript.org, randint(-2, 2) never returns -2 and returns 0 about twice as often as the other values. With both bounds negative it goes out of range: randint(-5, -1) can return 0. This is easy to hit in class, for example when picking a random velocity between -5 and 5. The cause is in the RapydScript random module. randint() uses int(), which truncates toward zero. Bruce reported it upstream in November 2024 (kovidgoyal/rapydscript-ng#185), and the fix there is kovidgoyal/rapydscript-ng#193. GlowScript ships its own copy of the compiler, so it needs the same fix here. This is the same kind of patch as 2debbe4 for randrange(). The one line changes to return a + randbelow(b - a + 1) in: lib/rapydscript/compiler.js package/RScompiler.3.2.min.js GlowScriptOffline/glowscript_libraries/RScompiler.3.2.min.js the build notes in lib/compiling/GScompiler.js, so the fix isn't lost on the next RapydScript update Older package versions are left as they are. I compiled test programs with the current and patched RScompiler.3.2.min.js and called each function 100,000 times. Before: randint(-2, 2) -2:0 -1:20279 0:39758 1:20004 2:19959 randint(-5, -1) -5:0 -4:19854 -3:19889 -2:20192 -1:20115 0:19950 randint(0, 10**10) returns negative numbers After: randint(-2, 2) -2:19696 -1:20045 0:20145 1:20045 2:20069 randint(-5, -1) -5:20056 -4:19995 -3:20144 -2:19972 -1:19833 0:0 randint(0, 10**10) stays in range @BruceSherwood @sspickle glowscript.org will need a redeploy to pick this up.

Open Graph Description: On glowscript.org, randint(-2, 2) never returns -2 and returns 0 about twice as often as the other values. With both bounds negative it goes out of range: randint(-5, -1) can return 0. This is easy...

X Description: On glowscript.org, randint(-2, 2) never returns -2 and returns 0 about twice as often as the other values. With both bounds negative it goes out of range: randint(-5, -1) can return 0. This is easy...

Opengraph URL: https://github.com/vpython/glowscript/pull/215

X: @github

direct link

Domain: github.com

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/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:fae8e31e-3fb0-0bf0-4f3f-43f547a6a733
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idACE8:19123C:1154C5:174904:6B0080FE
html-safe-noncee4e40e20887060ba8836edab120a0090359d8416aea9245bd0fd7e290044ccc0
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0U4OjE5MTIzQzoxMTU0QzU6MTc0OTA0OjZCMDA4MEZFIiwidmlzaXRvcl9pZCI6IjM2MjE3NzMzODUwODU3ODAyMjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac5bf0300d819d56d85f31b8bfbfa112c610e79a5cbdea3ccc6c2bc52719978a3e
hovercard-subject-tagpull_request:5076963387
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/vpython/glowscript/pull/215/files
twitter:imagehttps://avatars.githubusercontent.com/u/6792460?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/6792460?s=400&v=4
og:image:altOn glowscript.org, randint(-2, 2) never returns -2 and returns 0 about twice as often as the other values. With both bounds negative it goes out of range: randint(-5, -1) can return 0. This is easy...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None82c186f13e104004ab7bdb779f3195e59dd38bfde531aaa74b76470fc2462b83
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/vpython/glowscript git https://github.com/vpython/glowscript.git
octolytics-dimension-user_id1280757
octolytics-dimension-user_loginvpython
octolytics-dimension-repository_id187905631
octolytics-dimension-repository_nwovpython/glowscript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id187905631
octolytics-dimension-repository_network_root_nwovpython/glowscript
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
released1bc2aa1939001689f5ce935982c10a6138f745c
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/vpython/glowscript/pull/215/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fvpython%2Fglowscript%2Fpull%2F215%2Ffiles
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%2Fvpython%2Fglowscript%2Fpull%2F215%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=vpython%2Fglowscript
Reloadhttps://github.com/vpython/glowscript/pull/215/files
Reloadhttps://github.com/vpython/glowscript/pull/215/files
Reloadhttps://github.com/vpython/glowscript/pull/215/files
vpythonhttps://github.com/vpython
glowscripthttps://github.com/vpython/glowscript
Codehttps://github.com/vpython/glowscript
Issues9 (9)https://github.com/vpython/glowscript/issues
Pull requests2 (2)https://github.com/vpython/glowscript/pulls
Actionshttps://github.com/vpython/glowscript/actions
Projectshttps://github.com/vpython/glowscript/projects
Security and qualityhttps://github.com/vpython/glowscript/security
Insightshttps://github.com/vpython/glowscript/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fvpython%2Fglowscript%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fvpython%2Fglowscript%2Fissues%2Fnew%2Fchoose
sspicklehttps://github.com/sspickle
vpython:masterhttps://github.com/vpython/glowscript/tree/master
greatsong:fix-randint-negativehttps://github.com/greatsong/glowscript/tree/fix-randint-negative
Conversation 1 https://github.com/vpython/glowscript/pull/215
Commits 1 https://github.com/vpython/glowscript/pull/215/commits
Checks 0 https://github.com/vpython/glowscript/pull/215/checks
Files changed https://github.com/vpython/glowscript/pull/215/files
Please reload this pagehttps://github.com/vpython/glowscript/pull/215/files
Fix random.randint() with negative numbers https://github.com/vpython/glowscript/pull/215/files#top
Show all changes 1 commit https://github.com/vpython/glowscript/pull/215/files
2c8dc3d Fix random.randint() with negative numbers greatsong Oct 29, 2026 https://github.com/vpython/glowscript/pull/215/commits/2c8dc3dc9161808687766d501d58f9ce89416b2d
Clear filters https://github.com/vpython/glowscript/pull/215/files
Please reload this pagehttps://github.com/vpython/glowscript/pull/215/files
Please reload this pagehttps://github.com/vpython/glowscript/pull/215/files
RScompiler.3.2.min.js https://github.com/vpython/glowscript/pull/215/files#diff-50f3f718ff48010287d03a68f18aa6f64417d1048e5afe73c8cca752fc369ed2
GScompiler.js https://github.com/vpython/glowscript/pull/215/files#diff-c5e06395fc07406665368f378fd4aa946cee660714d79d39d85586c67e59a27f
compiler.js https://github.com/vpython/glowscript/pull/215/files#diff-21eb8966935b010d58675f21c5bccddd4453bf04f265127cd4ed00cb5e20680e
RScompiler.3.2.min.js https://github.com/vpython/glowscript/pull/215/files#diff-1e087fded8593149d31432ac69ef174d42b7b638de687c35459926f5160555ce
GlowScriptOffline/glowscript_libraries/RScompiler.3.2.min.jshttps://github.com/vpython/glowscript/pull/215/files#diff-50f3f718ff48010287d03a68f18aa6f64417d1048e5afe73c8cca752fc369ed2
View file https://github.com/greatsong/glowscript/blob/2c8dc3dc9161808687766d501d58f9ce89416b2d/GlowScriptOffline/glowscript_libraries/RScompiler.3.2.min.js
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/vpython/glowscript/pull/215/files
lib/compiling/GScompiler.jshttps://github.com/vpython/glowscript/pull/215/files#diff-c5e06395fc07406665368f378fd4aa946cee660714d79d39d85586c67e59a27f
View file https://github.com/greatsong/glowscript/blob/2c8dc3dc9161808687766d501d58f9ce89416b2d/lib/compiling/GScompiler.js
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/vpython/glowscript/pull/215/{{ revealButtonHref }}
https://github.com/vpython/glowscript/pull/215/files#diff-c5e06395fc07406665368f378fd4aa946cee660714d79d39d85586c67e59a27f
https://github.com/vpython/glowscript/pull/215/files#diff-c5e06395fc07406665368f378fd4aa946cee660714d79d39d85586c67e59a27f
lib/rapydscript/compiler.jshttps://github.com/vpython/glowscript/pull/215/files#diff-21eb8966935b010d58675f21c5bccddd4453bf04f265127cd4ed00cb5e20680e
View file https://github.com/greatsong/glowscript/blob/2c8dc3dc9161808687766d501d58f9ce89416b2d/lib/rapydscript/compiler.js
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/vpython/glowscript/pull/215/files
package/RScompiler.3.2.min.jshttps://github.com/vpython/glowscript/pull/215/files#diff-1e087fded8593149d31432ac69ef174d42b7b638de687c35459926f5160555ce
View file https://github.com/greatsong/glowscript/blob/2c8dc3dc9161808687766d501d58f9ce89416b2d/package/RScompiler.3.2.min.js
Open in desktop https://desktop.github.com
Please reload this pagehttps://github.com/vpython/glowscript/pull/215/files
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.