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
| Name | Type | Description |
|---|---|---|
source | RandomSource | A source of unsigned 32-bit integers; crypto by default where optional. |
n | number | 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));0What it prints (run when this page was built)