'use strict'; /** * Seedable mulberry32 RNG, so the game core stays deterministic in tests * and (later) for multiplayer replays. */ function createRng (seed) { var a = (seed >>> 0) || 1; return function rng () { a |= 0; a = a + 0x6D2B79F5 | 0; var t = Math.imul(a ^ a >>> 15, 1 | a); t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t; return ((t ^ t >>> 14) >>> 0) / 4294967296; }; } function pickIndex (rng, count) { var n = count | 0; if (n <= 0) { return 0; } return Math.floor(rng() * n) % n; } function pickFrom (rng, list) { if (!list || !list.length) { return undefined; } return list[pickIndex(rng, list.length)]; } var Rng = { create: createRng, pickIndex: pickIndex, pickFrom: pickFrom }; if (typeof module !== 'undefined' && module.exports) { module.exports = Rng; } else if (typeof globalThis !== 'undefined') { globalThis.Rng = Rng; }