roll
Roll is a node.js package for rolling dice and adding modifiers (such as "2d6+1").
How To Use (From Shell)
npm)
Installation (via$ npm install -g roll
Usage
$ roll 2d6+39$ roll d2015$ roll d%99$ roll -d 2d20Dice: 13, 8Total: 21$ roll --detail 5d%Dice: 45, 86, 86, 4, 72Total: 293
How To Use (As Library)
npm)
Installation (via$ npm install roll
Usage
Get an instance of the library:
var Roll = roll = ;
Rolling a single die:
var oneDie = roll;console; //random number between 1 and 6 (inclusive)
Rolling multiple dice:
var twoTwenties = roll;console; //random number between 2 and 40 (inclusive)
Rolling multiple sets of dice:
var bunchOfDice = roll;console; //random number between 3 and 52 (inclusive)
Rolling a percentage:
var chance = roll; //same as '1d100', 'd100', or '1d%'console; //random number between 1 and 100 (inclusive)
Simple calculation (+, -, *, /):
var attack = roll;console; //random number between 3 and 8 (inclusive)
Seeing what was rolled, rather than the sum:
var yahtzee = roll;console; //yahtzee.rolled will return something like [5, 2, 4, 6, 1] rather than the sum var blessedSneaker = roll;console; // blessedSneaker.rolled will return an array containing an array for each component that is a roll of the dice, in the order in which they occurred, e.g. [[19,3],[1]]
Getting the highest two dice of the set:
var pickBestTwo = roll; //roll 6 dice and give me the 2 highestconsole; //pickBestTwo.calculations[0] is the same as .result, .calculations[1] is prior to the sum operation
Processing rolls without parsing a string:
var attack = roll;console; //random number between 3 and 8 (inclusive)
Using custom transformations:
var { return results;};var noOnes = roll;
Using a custom seed:
var srand = ; //https://github.com/isaacs/node-srand (npm install srand)srand; roll = { return srand;}; console;
Validating user input:
var userInput = 'this isn\'t a valid roll' valid = roll; if !valid console;
Credits
Inspired by Phillip Newton's Games::Dice.