Skip to content

Commit

Permalink
⚡️ Faster Mersenne-Twister (#510)
Browse files Browse the repository at this point in the history
Changing the range of Mersenne-Twister to have it in int32 range. It drops one unneeded computation.
  • Loading branch information
dubzzz committed Jan 8, 2023
1 parent c2d6ee6 commit fdb6ec8
Show file tree
Hide file tree
Showing 5 changed files with 385 additions and 385 deletions.
6 changes: 3 additions & 3 deletions src/generator/MersenneTwister.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RandomGenerator } from './RandomGenerator';

class MersenneTwister implements RandomGenerator {
static readonly min: number = 0;
static readonly max: number = 0xffffffff;
static readonly min: number = -0x80000000;
static readonly max: number = 0x7fffffff;

static readonly N = 624;
static readonly M = 397;
Expand Down Expand Up @@ -79,7 +79,7 @@ class MersenneTwister implements RandomGenerator {
this.states = MersenneTwister.twist(this.states);
this.index = 0;
}
return y >>> 0;
return y;
}
}

Expand Down

0 comments on commit fdb6ec8

Please sign in to comment.