Reference · Streams, draws and seeds
pickfunction
One item of a list, each as likely as the next: one draw. Throws on an empty list.
Import it
import { pick } from "@johnmorrisdotca/tane";
Definition
function pick<T>(random: Random, items: readonly T[]): T
Parameters
| Name | Type | Description |
|---|---|---|
random | Random | A random source returning values in [0, 1). |
items | readonly T[] | The items to choose or shuffle; shuffle mutates this array, while shuffled copies it. |
Returns
T
One item of a list, each as likely as the next: one draw. Throws on an empty list.
Examples
import { mulberry32, pick } from "@johnmorrisdotca/tane";
const random = mulberry32(42);
console.log(pick(random, ["A", "B", "C"]));BWhat it prints (run when this page was built)