How-to
Exact odds
Read a distribution, threshold chances and exact integer outcome counts.
A probability for a total
import { parseNotation, distributionOf, chanceAtLeast, expectedTotal } from "@johnmorrisdotca/korokoro";
const spec = parseNotation("2d6")!;
const odds = distributionOf(spec);
console.log(chanceAtLeast(odds, 10), expectedTotal(odds));
console.log(odds.probabilities[7 - odds.min]);0.16666666666666669 7
0.16666666666666666Probabilities are fractions between zero and one, indexed from min, not by the total itself. The distribution describes the dice actually thrown, including the package's finite reroll and explosion caps.
Count ways without floating point
import { parseNotation, exactCounts } from "@johnmorrisdotca/korokoro";
const exact = exactCounts(parseNotation("2d6")!);
if (exact) console.log(exact.min, String(exact.outcomes), exact.counts.map(String));2 36 [
'1', '2', '3', '4',
'5', '6', '5', '4',
'3', '2', '1'
]exactCounts gives BigInt counts where that representation is supported, and null for unsupported rule combinations or spans. Do not stringify BigInt directly as JSON; convert it to text. distributionOf is the probability API for a normalized valid spec.
Odds with a held die
import { parseNotation, distributionHolding } from "@johnmorrisdotca/korokoro";
const odds = distributionHolding(parseNotation("2d6")!, [6, 3], [true, false]);
console.log(odds.min, odds.max);7 12Only the unheld die is uncertain. For repeated independent rolls, see chanceAnyAtLeast and expectedHighest. How it works explains which independence assumptions the engine uses.