Created
December 13, 2020 06:19
-
-
Save seyedi/9979ca5f3e23e2d08f759b550782bf1f to your computer and use it in GitHub Desktop.
For generating stable-but-random effects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function randomGenerator(seed) { | |
let state = seed; | |
const next = () => { | |
state |= 0; | |
state = (state + 0x6d2b79f5) | 0; | |
var t = Math.imul(state ^ (state >>> 15), 1 | state); | |
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; | |
return ((t ^ (t >>> 14)) >>> 0) / 4294967296; | |
}; | |
return { | |
next, | |
nextBetween: (from, to) => next() * (to - from) + from, | |
fork: () => randomGenerator(next() * 2 ** 32), | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment