Skip to content

🐛 Jump PRNG in infiniteStream loop after first iteration#6425

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/fix-prng-in-generate-function
Draft

🐛 Jump PRNG in infiniteStream loop after first iteration#6425
Copilot wants to merge 6 commits intomainfrom
copilot/fix-prng-in-generate-function

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

The PRNG was not being advanced between iterations in the infiniteStream loop, causing inconsistency with the toss mechanism in Tosser.ts.

Changes

  • Added jump() to Random class: Advances internal RNG by 42 values. The method intelligently checks if unsafeJump exists on the internal RNG and calls it if available, otherwise falls back to unsafeSkipN(this.internalRng, 42), matching the jump behavior in Tosser.ts
  • Call jump() after first iteration in infiniteStream: In StreamArbitrary, the PRNG now jumps after each value is yielded in the infinite stream generator loop, ensuring the first value is generated without jumping
  • Updated test infrastructure: Added jump mock to RandomHelpers and updated snapshots for infiniteStream tests reflecting the new value sequences

The jump amount (42) is consistent with existing usage in QualifiedParameters.ts and Tosser.ts. The fix is restricted to the infiniteStream code only, not affecting the general GeneratorArbitrary behavior.

Original prompt

solve #5054 by jumping in the prng before returning on generate


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@changeset-bot
Copy link

changeset-bot bot commented Dec 22, 2025

⚠️ No Changeset found

Latest commit: 12a6bf7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI and others added 2 commits December 22, 2025 14:43
Co-authored-by: dubzzz <5300235+dubzzz@users.noreply.github.com>
Co-authored-by: dubzzz <5300235+dubzzz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix PRNG behavior in generate function implementation 🐛 Jump PRNG before generate in GeneratorArbitrary Dec 22, 2025
Copilot AI requested a review from dubzzz December 22, 2025 14:49
// 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();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Restrict the jump to the infiniteStream code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! The PRNG jump is now restricted to the infiniteStream loop in StreamArbitrary.ts (line 33). Changes committed in 57fcb44.

Copilot AI and others added 2 commits December 22, 2025 14:59
Co-authored-by: dubzzz <5300235+dubzzz@users.noreply.github.com>
Co-authored-by: dubzzz <5300235+dubzzz@users.noreply.github.com>
Copilot AI changed the title 🐛 Jump PRNG before generate in GeneratorArbitrary 🐛 Jump PRNG in infiniteStream loop before generate Dec 22, 2025
Copilot AI requested a review from dubzzz December 22, 2025 15:04
let numSeenValues = 0;
const g = function* (arb: Arbitrary<T>, clonedMrng: Random) {
while (true) {
clonedMrng.unsafeJump();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot only run after first run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Jump now happens after the first value is yielded, not before. Changes committed in 12a6bf7.

* Jump the random number generator by a fixed amount
* @internal
*/
unsafeJump(): void {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot rename without unsafe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Renamed from unsafeJump() to jump(). Changes committed in 12a6bf7.

* @internal
*/
unsafeJump(): void {
unsafeSkipN(this.internalRng, 42);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot try to call unsafe jump when it exists on the prng

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copilot AI changed the title 🐛 Jump PRNG in infiniteStream loop before generate 🐛 Jump PRNG in infiniteStream loop after first iteration Jan 15, 2026
Copilot AI requested a review from dubzzz January 15, 2026 22:47
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.

2 participants