UNPKG

dicewerx

Version:

Standard dice notation parser and evaluator, written in TypeScript

26 lines (25 loc) 705 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * An N sided die that is capable of producing a random number between 1 and N * @remarks * Has its number of sides set at creation and get rolled immediately. * Can be rerolled on demand */ class Die { constructor(sides) { this.sides = Math.abs(sides); this.result = this.roll(); } /** * Rolls the die and returns the result * @remarks * Returns a random number between 1 and sides * @returns A random number between 1 and sides */ roll() { this.result = Math.floor(Math.random() * this.sides + 1); return this.result; } } exports.Die = Die;