Repository navigation
Seed the random generator only when rand() needs it - #682
Merged
Merged
Conversation
BSDRandom.setSeed() now only records the seed. The state table is built, and the first 310 values discarded, when the next value is requested. A runtime reset by eval() or execute() no longer pays for a seeding that most programs never use. The sequence of rand() values and the values returned by srand() are unchanged. Fixes #677 Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012oN69BYSPd66efoyXEYoRD
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #677
Problem
Every
eval()andexecute()resets the runtime withrandomNumberGenerator.setSeed(1).BSDRandom.setSeedfills the state table and discards 310 values, which the issue measures at about half the cost of a smalleval(), although very few programs callrand().Change
The laziness lives in
BSDRandomitself, so every caller benefits andAVM.javais not touched:setSeed()only records the seed and marks it as pending.nextDouble()builds the state table from the recorded seed first when one is pending.getSeed()is unchanged: it returns the last seed supplied, sosrand()still returns the previous seed (1 after a reset).The sequence of
rand()values is unchanged: the same seeding code runs, only later. There is no user-visible behavior change, sobehavior-changes.mdhas no new entry.Tests
BSDRandomTest(plain JUnit): seed reported before any value is drawn, reseeding restarts the sequence, reseeding after use matches a fresh generator, seed 0 behaves like seed 1, different seeds give different sequences.RandomSeedResetTest: one runtime reused for several executions (throughAwkTestSupport), with and withoutrand(), direct and indirect (@f()) calls, and the values returned bysrand(); plus the same check across severalAwk.eval()calls.mvn verifypasses locally: 1028 unit tests, and checkstyle, pmd and spotbugs report nothing.Generated by Claude Code