export interface SeededRNG { random(): number; install(): void; uninstall(): void; } export function createSeededRNG(seed: number): SeededRNG { let state = seed | 0; const originalRandom = Math.random; function random(): number { state = (state + 0x6D2B79F5) | 0; let t = Math.imul(state ^ (state >>> 15), 1 | state); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; } return { random, install() { Math.random = random; }, uninstall() { Math.random = originalRandom; }, }; }