Why this matters
Deterministic time and RNG remove flakiness and make failures reproducible.
In unit and integration tests, call a time-freeze utility and set a fixed random seed before exercising the system under test; unfreeze after assertions.
Deterministic time and RNG remove flakiness and make failures reproducible.
Side-by-side examples engineers can pattern-match during review.
test("creates token", () => {
const id = random(); // non-deterministic
const ts = now(); // wall-clock dependent
const token = createToken(id, ts);
assertMatches(token, /[A-Z0-9]+/);
});test("creates token", () => {
setRandomSeed(42);
freezeTime("2024-01-01T00:00:00Z");
const id = random();
const ts = now();
const token = createToken(id, ts);
assertEquals(token, "ABC123-20240101");
unfreezeTime();
});freezeTime("2024-01-01T00:00:00Z"); setRandomSeed(42);const ts = now(); const id = random(); // flakyFrom the same buckets as this rule.
Reject PRs adding real PAN/CVV in fixtures, seeds, or mocks. Only use Luhn-valid test PANs from the gateway or opaque tokens (e.g., tok_) and never include CVV. Add a check to fail if a PAN regex is matched. (PCI DSS data minimization)