// rng.ts provides seeded, reproducible pseudo-randomness, so a whole game // replays exactly from its seed. // mulberry32: small, fast, good-enough distribution for game-flavoured // randomness (home base placement, bot tie-breaking). Not cryptographic -- // nothing here needs to be. export const seeded = (seed: number): (() => number) => { let state = seed >>> 0; return (): number => { state = (state + 0x6d2b79f5) >>> 0; let t = state; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; }; // The one impure function in this module, called exactly once by main.ts // when no seed was pinned. Mirrors the convention game.ts's // generateHomeBases already set: game.ts and bot code never reach for // Math.random themselves -- the caller supplies the randomness, which is // what makes a whole game (home bases, every bot decision) replayable from // a single recorded seed. export const randomSeed = (): number => Math.floor(Math.random() * 2 ** 32);