Skip to content

Instantly share code, notes, and snippets.

@EsteveSegura
Created December 21, 2023 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EsteveSegura/c0ec622ad2bbf68bc49cf03f129df779 to your computer and use it in GitHub Desktop.
Save EsteveSegura/c0ec622ad2bbf68bc49cf03f129df779 to your computer and use it in GitHub Desktop.
PseudoRNG
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