Skip to content

Fix seeding collisions in the TypeScript module RNG - #6323

Open
bradleyshep wants to merge 1 commit into
masterfrom
bradley/ts-rng-seeding
Open

bradleyshep wants to merge 1 commit into
masterfrom
bradley/ts-rng-seeding

Conversation

@bradleyshep

Copy link
Copy Markdown
Contributor

Description of Changes

  • pcg32 rotates with >>> instead of >>.
  • The xoroshiro128+ state is filled from four successive PCG32 outputs instead of a single 32-bit value, as rand's seed_from_u64 does.

Each reducer and procedure transaction seeds its RNG from its timestamp. The signed shift and the 32-bit seed made different timestamps share the same stream. Across 1,000,000 consecutive microsecond timestamps, 243,733 produced the same first 16 bytes as an earlier timestamp. ctx.newUuidV4() could return duplicate UUIDs, which surfaced as Value with given unique identifier already exists. With this change: 0.

API and ABI breaking changes

None. The API is unchanged. A given timestamp now produces different random values than before. Transactions with the same timestamp still share values, as in the Rust bindings.

Rollback safety impact

n/a

Expected complexity level and risk

1

Testing

  • New test: 100,000 consecutive timestamps produce distinct 16-byte outputs. Fails on master, passes with this change.
  • pnpm exec vitest run tests/rng.test.ts
  • Full bindings-typescript lint, type build and unit tests (38 files, 477 tests)

@bradleyshep
bradleyshep marked this pull request as ready for review October 16, 2026 19:37

This branch has not been deployed

No deployments
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