Skip to content

Commit

Permalink
Fix random provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-wolfe committed Mar 23, 2018
1 parent f6418bf commit 04010c6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
16 changes: 14 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dice-typescript",
"version": "1.2.0",
"version": "1.3.0",
"description": "A TypeScript library for parsing dice rolling expressions, most commonly used in tabletop RPGs.",
"main": "./dist/index.js",
"scripts": {
Expand Down Expand Up @@ -36,6 +36,7 @@
"homepage": "https://github.com/trwolfe13/dice#readme",
"devDependencies": {
"@types/jasmine": "^2.8.6",
"@types/random-js": "^1.0.30",
"codacy-coverage": "^2.0.2",
"istanbul": "^0.4.5",
"jasmine-core": "2.5.2",
Expand All @@ -46,5 +47,8 @@
"rimraf": "^2.6.1",
"tslint": "^5.4.3",
"typescript": "^2.4.1"
},
"dependencies": {
"random-js": "^1.0.8"
}
}
10 changes: 8 additions & 2 deletions src/default-random-provider.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { RandomProvider } from "./random-provider";
import * as Random from "random-js";

export class DefaultRandomProvider implements RandomProvider {
constructor() { }

private random: Random;

constructor() {
this.random = new Random(Random.engines.mt19937().autoSeed());
}

numberBetween(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1)) + min;
return this.random.integer(min, max);
}
}

0 comments on commit 04010c6

Please sign in to comment.