[Web] Expose RNG state for deterministic restore#20034
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the ability to get and set the state of the internal LinearCongruentialGenerator (RNG) for deterministic restoration. It adds getRNGState and setRNGState methods to the Instance class, and corresponding getState and setState methods to the LinearCongruentialGenerator class, along with validation checks and comprehensive unit tests. I have no feedback to provide as there are no review comments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
guan404ming
left a comment
There was a problem hiding this comment.
LGTM, left some nits. Thanks!
| constructor() { | ||
| this.modulus = 2147483647; // 2^32 - 1 | ||
| this.multiplier = 48271; // between 2^15 and 2^16 | ||
| this.modulus = 2147483647; // 2^31 - 1 |
| ); | ||
| } | ||
| this.rand_state = state; | ||
| this.checkRandState(); |
There was a problem hiding this comment.
I think this one seems redundant, the explicit checks already guarantee the invariant.
| */ | ||
| const tvmjs = require("../../dist"); | ||
|
|
||
| function createRNGOnlyInstance() { |
There was a problem hiding this comment.
The Object.create(Instance.prototype) + empty stub couples the test to uniform() internals; the LCG-level test already covers determinism, so comparing rng.randomFloat() sequences directly would be simpler.
Expose tvmjs RNG state so callers can save and restore deterministic sampling progress. Adds the following:
RNGStateas the exported state type forLinearCongruentialGeneratorLinearCongruentialGenerator.getState()LinearCongruentialGenerator.setState(state)Instance.getRNGState()Instance.setRNGState(state)