Skip to the content

Korokoroコロコロ

Roll mixed dice or type notation, compare exact probabilities, keep a history and replay seeded rolls.

Korokoro describes something small rolling in Japanese. About the name

Contents

Reference · Rolls and exact odds

rollfunction

Throw the dice. The source is crypto unless a seeded one is given. The third argument is when the roll is made, in epoch milliseconds (now, unless given), or options: { at, maxDice }. A spec asking for more than ten dice is brought to ten unless maxDice says otherwise, up to MAX_DICE_BY_CODE.

Import it

import { roll } from "@johnmorrisdotca/korokoro";

Definition

function roll(spec: Partial<RollSpec>, source?: RandomSource, when?: number | RollOptions): Roll

Parameters

NameTypeDescription
specPartial<RollSpec>

Dice counts, sides, rules and modifier; omitted fields use the documented defaults.

source (optional)RandomSource

A source of unsigned 32-bit integers; crypto by default where optional.

when (optional)number | RollOptions

Epoch milliseconds, or roll options including the time and maximum dice.

Returns

Roll

The completed roll, including its spec, faces, kept mask, total, seed and timestamp.

Examples

import { roll } from "@johnmorrisdotca/korokoro";
import { normalizeSpec, seededSource } from "@johnmorrisdotca/korokoro";
const spec = normalizeSpec({ count: 2, sides: 6 });
console.log(roll(spec, seededSource("table"), 0).faces);
[ 1, 2 ]

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/korokoro 1.16.0.