Last active
October 23, 2022 15:46
-
-
Save rasmusmerzin/9876f831b0d58b8d6821b883687e4cd6 to your computer and use it in GitHub Desktop.
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
// nolib ANSI RNG | |
export const m = 2 ** 31; // just outside of i32 | |
export const a = 1103515245; | |
export const c = 12345; | |
// returns integer [0; 2 ** 31 -1] | |
export function rand(seed: number): () => number { | |
return () => (seed = (a * seed + c) % m | 0); | |
} | |
// returns float [0; 1] | |
export function randf(seed: number): () => number { | |
const rint = rand(seed); | |
return () => rint() / (m - 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment