Skip to content

Commit

Permalink
⚡ Improve performances of uniform distributions on wide ranges (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Jul 29, 2020
1 parent a52bbb1 commit a7cc22e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"coverage": "cat ./coverage/lcov.info | coveralls",
"build:bench:old": "tsc --target es6",
"build:bench:new": "tsc --target es6 --outDir lib-new/",
"auto:bench": "git stash && yarn build:bench:old && git stash pop && yarn build:bench:new && node perf/benchmark.js"
"bench": "node perf/benchmark.cjs",
"auto:bench": "git stash && yarn build:bench:old && git stash pop && yarn build:bench:new && yarn bench"
},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions src/distribution/UniformIntDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function uniformIntInternal(from: number, diff: number, rng: RandomGenerator): [

// Compute number of iterations required to have enough random
// to build uniform entries in the asked range
let FinalNumValues = 1;
let NumIterations = 0;
let FinalNumValues = NumValues * NumValues;
let NumIterations = 2; // At least 2 (at this point in the code)
while (FinalNumValues < diff) {
FinalNumValues *= NumValues;
++NumIterations;
Expand Down

0 comments on commit a7cc22e

Please sign in to comment.