The Drift Log · Model independence and repeatable builds
Seeded Randomness for Byte‑Identical Test Builds
14 November 2026 · 3 min read · 494 words · established

Seeding global randomness lets you produce byte‑identical builds, turning flaky tests into reliable CI checks.
The hidden seed problem
Your CI pipeline flashes green, then red, then green again for the same commit. The test suite pulls a random identifier, shuffles an array, or generates a UUID. When the same code runs twice, the byte stream of the artefact changes. The failure is not a bug in the logic; it is uncontrolled randomness leaking into the build. Flaky tests become noise. Engineers start ignoring failures. Trust in the pipeline erodes.
Seeding every source
The first step is to locate every source of nondeterminism. Common culprits are Math.random(), crypto‑secure generators, and library helpers that fall back to the system clock. Replace each call with a seeded variant. In Node, the seedrandom package can wrap the global Math.random:
import seedrandom from 'seedrandom';
const rng = seedrandom('shpbl-seed-2024');
global.Math.random = rng;
For crypto‑level IDs, use a deterministic counter or a hash of the seed and a monotonic index. If a third‑party library does not expose a seed, initialise it once at process start and avoid re‑initialising per test file.
Do not alter test expectations. The test code continues to call Math.random() as before; the seed guarantees the same sequence on every run. The only change is a single import at the top of the test harness.
Verifying byte‑identical runs
Once the seed is fixed, verify that the compiled artefact is byte‑identical across runs. Run the build twice on a clean checkout, capture the output archive, and compare checksums.
npm run build && sha256sum dist/bundle.js > /tmp/first.sha
git clean -fdx && npm ci && npm run build && sha256sum dist/bundle.js > /tmp/second.sha
diff /tmp/first.sha /tmp/second.sha
If the diff is empty, the build is repeatable. If a mismatch appears, the source of nondeterminism is still present. Typical missed sources are map iteration order and JSON.stringify on objects with non‑deterministic key order. Pin the iteration order by sorting keys before serialisation, or use a library that guarantees order.
The verification step should be part of the CI pipeline. Add a job that fails the build if the checksum changes. Now a flaky test becomes a hard failure, and the team can address it immediately.
SHPBL’s repeatable‑build guarantee
SHPBL delivers a model‑independent library whose artefacts are computed rather than generated. The release archives are sealed by published checksums, providing a root of trust for byte‑identical results. A certification harness executes each artifact and records a verdict – CERTIFIED, PROVISIONAL, INCONCLUSIVE, or FAILED – so you can see whether repeatability has been proven. The same tools are available via an MCP server, a plain HTTP API, a typed TypeScript client, or an offline file‑based edition. For a concrete example of how seeded randomness removes flakiness, see our pillar post on Model Independence and Repeatable Software Builds. If you want to try the approach on a real repository, start with a free evaluation at /evaluation.
What to do on Monday
Add the seedrandom import to your test harness. Pick a fixed seed string and assign it to global.Math.random. Run the build twice, compare the SHA‑256 hashes, and fail the CI if they differ. You will see flaky failures disappear, and the CI will once again be a reliable gate.
This post supports the longer argument in Model Independence and Repeatable Software Builds.
Keep reading
Next in the log
- Model Independence and Repeatable Software Builds
Runtime model variance and non-reproducible builds compound to break production systems. Here is how to isolate probabilistic logic and pin artifacts.
- Capturing Build-Time Environment to Freeze Artifact Output
Scrub ambient host variables with an allowlist and record environment manifests to guarantee byte-for-byte repeatable build artifacts.
- Deterministic Ordering of JSON Keys for Stable Snapshots
Flaky CI snapshot diffs caused by nondeterministic JSON key order can be eliminated with SHPBL’s certified, repeatable canonicalisation routine.
The Strategic Master Library · written and reviewed under the house's own epistemic rules: nothing claimed that we cannot show.