🐛 Jump PRNG in infiniteStream loop after first iteration#6425
🐛 Jump PRNG in infiniteStream loop after first iteration#6425
Conversation
|
Co-authored-by: dubzzz <5300235+dubzzz@users.noreply.github.com>
Co-authored-by: dubzzz <5300235+dubzzz@users.noreply.github.com>
| // possibly leading from totally different sets of functions. | ||
| // In other words: `preBuiltValue !== undefined && context.history.length === 0` is a legit case! | ||
| // If we start to mismatch we run a new random value computation | ||
| localMrng.unsafeJump(); |
Co-authored-by: dubzzz <5300235+dubzzz@users.noreply.github.com>
Co-authored-by: dubzzz <5300235+dubzzz@users.noreply.github.com>
| let numSeenValues = 0; | ||
| const g = function* (arb: Arbitrary<T>, clonedMrng: Random) { | ||
| while (true) { | ||
| clonedMrng.unsafeJump(); |
| * Jump the random number generator by a fixed amount | ||
| * @internal | ||
| */ | ||
| unsafeJump(): void { |
There was a problem hiding this comment.
Done! Renamed from unsafeJump() to jump(). Changes committed in 12a6bf7.
| * @internal | ||
| */ | ||
| unsafeJump(): void { | ||
| unsafeSkipN(this.internalRng, 42); |
There was a problem hiding this comment.
@copilot try to call unsafe jump when it exists on the prng
There was a problem hiding this comment.
Done! The jump() method now checks if unsafeJump exists on the internal RNG and calls it if available, otherwise falls back to unsafeSkipN. Changes committed in 12a6bf7.
…k for unsafeJump Co-authored-by: dubzzz <5300235+dubzzz@users.noreply.github.com>
The PRNG was not being advanced between iterations in the
infiniteStreamloop, causing inconsistency with thetossmechanism inTosser.ts.Changes
jump()toRandomclass: Advances internal RNG by 42 values. The method intelligently checks ifunsafeJumpexists on the internal RNG and calls it if available, otherwise falls back tounsafeSkipN(this.internalRng, 42), matching the jump behavior inTosser.tsjump()after first iteration in infiniteStream: InStreamArbitrary, the PRNG now jumps after each value is yielded in the infinite stream generator loop, ensuring the first value is generated without jumpingjumpmock toRandomHelpersand updated snapshots for infiniteStream tests reflecting the new value sequencesThe jump amount (42) is consistent with existing usage in
QualifiedParameters.tsandTosser.ts. The fix is restricted to the infiniteStream code only, not affecting the general GeneratorArbitrary behavior.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.