// Seeded randomness. Rules, city and traffic draw from these, never from Math.random, // so the same seed always builds the same city and plays the same game. /** A small seeded random number generator (mulberry32): returns a function giving floats in [0, 1). */ export function rng(seed) { let a = seed >>> 0; return () => { a = (a + 0x6d2b79f5) >>> 0; let t = a; t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } /** A float in [0, 1) that depends only on its integer arguments: for per-cell choices. */ export function hash(...ints) { let h = 0x9e3779b9; for (const n of ints) { h = Math.imul(h ^ (n | 0), 0x85ebca6b); h ^= h >>> 13; h = Math.imul(h, 0xc2b2ae35); h ^= h >>> 16; } return (h >>> 0) / 4294967296; } export const pick = (random, list) => list[Math.floor(random() * list.length) % list.length]; export const between = (random, lo, hi) => lo + random() * (hi - lo);