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

samplefunction

count items of a list, no item twice, in the order drawn: a partial Fisher–Yates, one draw each. Asking for more than the list holds gives the whole list, shuffled.

Import it

import { sample } from "@johnmorrisdotca/tane";

Definition

function sample<T>(random: Random, items: readonly T[], count: number): 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.

countnumber

The number of items or draws requested.

Returns

T[]

count items of a list, no item twice, in the order drawn: a partial Fisher–Yates, one draw each. Asking for more than the list holds gives the whole list, shuffled.

Examples

import { mulberry32, sample } from "@johnmorrisdotca/tane";

const random = mulberry32(42);
console.log(sample(random, ["A", "B", "C", "D"], 3));
[ 'C', 'A', 'D' ]

What it prints (run when this page was built)

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