Skip to content

Fix random.randint() with negative numbers (port of glowscript#215) - #5

Open
sspickle wants to merge 2 commits into
mainfrom
fix/randint-negative
Open

sspickle wants to merge 2 commits into
mainfrom
fix/randint-negative

Conversation

@sspickle

Copy link
Copy Markdown
Contributor

Ports vpython/glowscript#215 (merged as b8a6fa1). This runner serves trinket's Web VPython 3.2.3, and webvpython.org for every program that isn't marked wasm, so both sites have the randint bug until this is deployed.

randint() used int(), which truncates toward zero:

before after
randint(-2, 2) never −2, 0 twice as often −2..2, even
randint(-5, -1) never −5, returns 0 −5..−1, even
randint(0, 10**10) 8,631 of 20,000 out of range 0 out of range

(100,000 calls each, through the GlowScriptOffline compile-and-run pipeline, with this branch's package/RScompiler.3.2.min.js swapped in.)

What changed

  • lib/rapydscript/compiler.js and lib/compiling/GScompiler.js are copied from glowscript b8a6fa1. Both were byte-identical to glowscript's versions before the fix.
  • package/RScompiler.3.2.min.js is rebuilt with build_package.py. glow, RSrun and compiler rebuild byte-identical, so only the RapydScript compiler changes.
  • A second commit extends .gitignore to .env, .env.* and *.pem.

Note: main was behind the live deploy

The June deploy to gs://rswvprunner was built from 6db610b (the lazy $('body') print fix), which was only on the lazy-body-eval branch. I fast-forwarded main to it before branching. Rebuilding main now reproduces every live file exactly (glow 15877990…, RScompiler ada77756…, RSrun 2735844b…).

Deploying

  1. Merge, then run do_build.sh (TRUSTED_HOST from build.env).
  2. Check that the live package/RScompiler.3.2.min.js has sha256 starting 6376aa0899c68a2a.
  3. Trinket pins these files by sha256. A picup PR will update RSCOMPILER_SHA256 and GLOWSCRIPT_PACKAGE_BUILD to match.

🤖 Generated with Claude Code

sspickle and others added 2 commits October 31, 2026 07:43
…t#215)

randint() used int(), which truncates toward zero, so randint(-2, 2)
never returned -2 and randint(-5, -1) could return 0; past 2**31 it went
negative. Same one-line fix as glowscript b8a6fa1 / upstream
rapydscript-ng#193: return a + randbelow(b - a + 1).

lib/rapydscript/compiler.js and lib/compiling/GScompiler.js are copied
from glowscript b8a6fa1 (both were identical to glowscript before the
fix). package/RScompiler.3.2.min.js is rebuilt with build_package.py;
glow, RSrun and compiler rebuild byte-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QNw6KLiif2r9zSoSQug4iL
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QNw6KLiif2r9zSoSQug4iL
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.

1 participant