Created
December 21, 2023 00:42
-
-
Save EsteveSegura/c0ec622ad2bbf68bc49cf03f129df779 to your computer and use it in GitHub Desktop.
PseudoRNG
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
class LinearRadGen{ | |
constructor(seed) { | |
this.a = 1103515245; | |
this.c = 12345; | |
this.m = Math.pow(2,32); | |
this.seed = seed; | |
} | |
next() { | |
this.seed = (this.a * this.seed + this.c) % this.m; | |
return this.seed / this.m; | |
} | |
} | |
const seed = Date.now(); | |
const rng = new LinearRadGen(seed); | |
console.log(rng.next()); | |
console.log(rng.next()); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment