UNPKG

tycho-solver

Version:

Evolutionary computation and optimization library

25 lines 703 B
// Simple seeded RNG (LCG) for reproducible runs export class RNG { state; constructor(seed) { if (seed === undefined || seed === null) { // derive seed from current time seed = Date.now() & 0xffffffff; } this.state = seed >>> 0; } // returns float in [0,1) random() { // constants from Numerical Recipes this.state = (1664525 * this.state + 1013904223) >>> 0; return (this.state & 0xffffffff) / 0x100000000; } // returns integer in [0, n) int(n) { return Math.floor(this.random() * n); } } export function seededRandom(seed) { return new RNG(seed); } //# sourceMappingURL=rng.js.map