Created
May 23, 2019 13:25
-
-
Save signalwerk/377fdd8e453a0986e294c7767758e19c to your computer and use it in GitHub Desktop.
Pseudorandom number generator (PRNG)
This file contains 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
// 1993 Park-Miller linear congruential generator (LCG) | |
// https://en.wikipedia.org/wiki/Lehmer_random_number_generator | |
// Source: https://gist.github.com/blixt/f17b47c62508be59987b | |
// usage: | |
// let rand = LCG(42); | |
// rand() → 0.000944073311984539 | |
// rand() → 0.5713628428056836 | |
// rand() → 0.2557850731536746 | |
const LCG = s => { | |
return () => { | |
s = Math.imul(48271, s) | 0 % 2147483647; | |
return (s & 2147483647) / 2147483648; | |
}; | |
}; | |
export default LCG; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment