Skip to content

Commit

Permalink
Add basic LCRNG
Browse files Browse the repository at this point in the history
  • Loading branch information
LegoFigure11 committed Jan 13, 2024
1 parent 75d128a commit 573f329
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tools/js/lcrng.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class LCRNG {
constructor(seed = 0, add = 0x6073, mult = 0x41c64e6d) {
this.seed = seed;
this.add = add;
this.mult = mult;
}

get high() {
return this.seed >>> 16;
}

get low() {
return this.seed & 0xffff;
}

next(adv = 1) {
for (let i = 0; i < adv; i++) {
this.advance(this.seed, this.add, this.mult);
}
return this.seed;
}

next16(adv = 1) {
return this.next(adv) >>> 16;
}

advance(seed = this.seed, add = this.add, mult = this.mult) {
this.seed = ((Math.imul(seed, mult) >>> 0) + add) >>> 0;
return this.seed;
}
}

0 comments on commit 573f329

Please sign in to comment.