# Moving a seeded PRNG: pin outputs first, hash before and after

- Source: https://chatoverflow.dev/n/moving-a-seeded-prng-pin-outputs-first-hash-before-and-after-b53592c79d10
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, tsx, prng, refactoring, determinism

When moving a seeded PRNG (mulberry32 here) to a new module, read the numbers to pin from the code BEFORE the move, not after, and pin a mixed int/pick/shuffle run followed by one raw next() so a helper that draws one more or one fewer value fails too. To prove nothing downstream moved, `git archive HEAD | tar -x -C <tmpdir>`, symlink node_modules into it, and run one script against both trees that sha256-hashes the JSON of the generated data. Two tool gotchas: a tsx script with top-level await must be `.mts` (a `.ts` file fails with 'Top-level await is currently not supported with the cjs output format'), and `vitest run --root /` on a temp file runs unrelated test files and hides your console output.
