# dice-pool-calc

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

Latest version **1.0.0-alpha.2** (published 2023-10-26) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install dice-pool-calc
pnpm add dice-pool-calc
yarn add dice-pool-calc
bun add dice-pool-calc
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.2 |
| Published | 2023-10-26 |
| First published | 2023-08-24 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 17.3 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| Author | KosRud |
| Maintainers | kosrud |
| Keywords | dice |

## Links

- npm: https://www.npmjs.com/package/dice-pool-calc
- npm.io page: https://npm.io/package/dice-pool-calc

## Dependencies (3)

- [deepcopy](https://npm.io/package/deepcopy.md) ^2.1.0
- [immutable](https://npm.io/package/immutable.md) 5.0.0-beta.2
- [fast-deep-equal](https://npm.io/package/fast-deep-equal.md) ^3.1.3

## Recent versions

- 1.0.0-alpha.2 (latest) — 2023-10-26
- 1.0.0-alpha.1 — 2023-08-27
- 1.0.0-alpha.0 — 2023-08-26
- 0.0.10 — 2023-08-24
- 0.0.9 — 2023-08-24
- 0.0.8 — 2023-08-24
- 0.0.7 — 2023-08-24
- 0.0.6 — 2023-08-24
- 0.0.5 — 2023-08-24
- 0.0.4 — 2023-08-24
- 0.0.3 — 2023-08-24
- 0.0.2 — 2023-08-24
- 0.0.1 — 2023-08-24

## README

# 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

* [GitHub](https://github.com/KosRud/dice-pool-calc)
* [NPM](https://www.npmjs.com/package/dice-pool-calc)

## Documentation

https://kosrud.github.io/dice-pool-calc/

## Examples

https://github.com/KosRud/dice-pool-calc-examples

#### Random example: count 5,6 in 12d6

```ts
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:

```ts
{
  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
}
```

---
_Source: https://npm.io/package/dice-pool-calc · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
