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

randomIntfunction

A fair integer in [0, n). Rejection sampling, never next() % n: the modulo leans towards the low faces whenever n does not divide 2^32, and a d6 or a d10 does not.

Import it

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

Definition

function randomInt(source: RandomSource, n: number): number

Parameters

NameTypeDescription
sourceRandomSource

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

nnumber

The threshold, denominator or exclusive upper bound used by this call.

Returns

number

A fair integer in [0, n). Rejection sampling, never next() % n: the modulo leans towards the low faces whenever n does not divide 2^32, and a d6 or a d10 does not.

Examples

import { randomInt } from "@johnmorrisdotca/korokoro";
import { seededSource } from "@johnmorrisdotca/korokoro";
console.log(randomInt(seededSource("table"), 6));
0

What it prints (run when this page was built)

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