diced

dice distributions - probabilities of dice rolls

npm install diced
4 downloads in the last month

Diced

Dice distributions - probabilities of dice rolls

var diced = require('diced')
var d = diced('2d6')

for(var i=0; i < d.length; i++){
  var roll = i + d.low
  console.log('Roll a %d: %d%', roll, (d[i] * 100).toFixed(2))
}

Result:

Roll a 2: 2.78%
Roll a 3: 5.56%
Roll a 4: 8.33%
Roll a 5: 11.11%
Roll a 6: 13.89%
Roll a 7: 16.67%
Roll a 8: 13.89%
Roll a 9: 11.11%
Roll a 10: 8.33%
Roll a 11: 5.56%
Roll a 12: 2.78%

diced(diceString)

The notation for diceString is NdS, where N is the number of dice used and S is the number of sides each die has. Examples:

// two 6-sided die
diced('2d6')
// three 12-sided die
diced('3d12')

var d = diced('2d6')

The result of diced is an Array-like object.

d[n]

The probability of a roll n, where n=0 is the probability of the lowest possible roll

d.low

The lowest possible roll

d.high

The highest possible roll

d.quantity

The number of dice in the distribution set

d.sides

The number of sides for a single die

npm loves you