1.0.0-alpha.2 • Published 7 months ago

dice-pool-calc v1.0.0-alpha.2

Weekly downloads
-
License
BSD-3-Clause
Repository
-
Last release
7 months ago

dice-pool-calc

A typescript library for efficiently calculating dice probabilities with arbitrarily complex rules.

  • easily handles hudreds of dice
  • enumerates all possible values

Links

Documentation

https://kosrud.github.io/dice-pool-calc/

Examples

https://github.com/KosRud/dice-pool-calc-examples

Random example: count 5,6 in 12d6

import * as stats from "dice-pool-calc/stats";
import { Die } from "dice-pool-calc";

// Count rolls of 5 or higher in a pool of 12d6

const countSuccess = (accumulator: number, outcome: number) => {
  if (outcome >= 5) {
    accumulator++;
  }
  return accumulator;
};

const successPool = Die.pool(countSuccess, 0, Die.nd(12, 6));

const average = stats.average(successPool);
const median = stats.median(successPool);

console.log({ outcomes: successPool.outcomes.toJS(), average, median });

output:

{
  outcomes: {
    '0': 0.007707346629258935,
    '1': 0.0462440797755536,
    '2': 0.12717121938277243,
    '3': 0.21195203230462067,
    '4': 0.2384460363426983,
    '5': 0.19075682907415864,
    '6': 0.11127481695992587,
    '7': 0.04768920726853966,
    '8': 0.014902877271418646,
    '9': 0.0033117505047596998,
    '10': 0.000496762575713955,
    '11': 0.00004516023415581409,
    '12': 0.0000018816764231589197
  },
  average: 4,
  median: 6
}
1.0.0-alpha.2

7 months ago

1.0.0-alpha.1

9 months ago

1.0.0-alpha.0

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago