class Xoroshiro128StarStar { constructor(seed = 1n) { if (BigInt(seed) === 0n) { throw new Error("xoroshiro128** must be seeded with a non-zero state") } this.s = [BigInt(seed) & 0xffffffffffffffffn, (BigInt(seed) >> 64n) & 0xffffffffffffffffn]; } next() { function trunc64(x) { return x & 0xffffffffffffffffn; } function rotl(x, k) { return (x << k) | (x >> (64n - k)); } let [s0, s1] = this.s; const r = trunc64(rotl(s0 * 5n, 7n) * 9n); s1 ^= s0; s0 = trunc64(rotl(s0, 24n) ^ s1 ^ (s1 << 16n)); s1 = trunc64(rotl(s1, 37n)); this.s = [s0, s1]; return r; } }
https://files.mastodon.social/media_attachments/files/111/625/402/790/225/715/original/f9214ab935f52935.png