// A seeded random source (mulberry32): the same seed draws the same // numbers, so a run that failed can be run again exactly. export function seeded (seed) { let state = Number(seed) >>> 0 || 1 const rand = () => { 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 } return { rand, pick: a => a[Math.floor(rand() * a.length)], chance: p => rand() < p } }