Reference · Rolls and exact odds
rollHeldfunction
Hold some dice of a roll and throw the rest again, as Yacht and Farkle do.
held[i] is whether face i stays. The dice not held are thrown in order
from the source, so from a seed the second roll replays like the first.
The roll that comes back says which faces were held. Only plain dice can be
held (canHold); anything else is a RangeError, as is a held that does
not fit the roll.
Import it
import { rollHeld } from "@johnmorrisdotca/korokoro";
Definition
function rollHeld(previous: Roll, held: readonly boolean[], source?: RandomSource, at?: number): Roll
Parameters
| Name | Type | Description |
|---|---|---|
previous | Roll | The roll whose held dice must remain unchanged. |
held | readonly boolean[] | A mask marking dice whose faces stay fixed. |
source (optional) | RandomSource | A source of unsigned 32-bit integers; crypto by default where optional. |
at (optional) | number | The recorded time in epoch milliseconds. |
Returns
Roll
Hold some dice of a roll and throw the rest again, as Yacht and Farkle do. held[i] is whether face i stays. The dice not held are thrown in order from the source, so from a seed the second roll replays like the first. The roll that comes back says which faces were held. Only plain dice can be held (canHold); anything else is a RangeError, as is a held that does not fit the roll.
Examples
import { rollHeld } from "@johnmorrisdotca/korokoro";
import { normalizeSpec, rollFrom, seededSource } from "@johnmorrisdotca/korokoro";
const spec = normalizeSpec({ count: 2, sides: 6 });
const sample = rollFrom(spec, [2, 5], "saved", 0, null)!;
console.log(rollHeld(sample, [true, false], seededSource("next"), 1).faces);[ 2, 2 ]What it prints (run when this page was built)