Skip to the content

Tane種

Reproduce numbers from a seed, shuffle or pick items, share a daily puzzle and resume a saved stream.

Tane means seed in Japanese. About the name

Contents

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

NameTypeDescription
randomRandom

A random source returning values in [0, 1).

itemsreadonly 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"]));
B

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/tane 1.3.0.