1.0.0 • Published 6 years ago

dice-probabilities v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

Dice Probabilities

Compute the probability of rolling p on n s-sided dice.

The formula for the probability comes from Wolfram; the multiplicative formula for the binomial coefficient comes from Wikipedia.

This page is just interesting: http://mathforum.org/library/drmath/view/52207.html

Installation

Usage

This module provides one function to compute the probability of rolling a specific number and another to roll dice.

const dice_prob = require('dice-probabilities');

// Probability for rolling 12 on 2 6-sided dice:
let p = dice_prop.P(12, 2, 6);

// Cumulative probability for rolling under 11 on 3 6-sided dice:
let cp = 0.0;
for (let i = 3; i <= 18; i++) {
  cp += dice_prop.P(i, 3, 6);
}

let r = dice_prop.roll(2, 6);