Reference · Streams, draws and seeds
shufflefunction
The list in place, in a random order (Fisher–Yates, from the end): one draw for each item but the first. Returns the same array.
Import it
import { shuffle } from "@johnmorrisdotca/tane";
Definition
function shuffle<T>(random: Random, items: T[]): T[]
Parameters
| Name | Type | Description |
|---|---|---|
random | Random | A random source returning values in [0, 1). |
items | T[] | The items to choose or shuffle; shuffle mutates this array, while shuffled copies it. |
Returns
T[]
The list in place, in a random order (Fisher–Yates, from the end): one draw for each item but the first. Returns the same array.
Examples
import { mulberry32, shuffle } from "@johnmorrisdotca/tane";
const random = mulberry32(42);
console.log(shuffle(random, ["A", "B", "C"]));[ 'C', 'A', 'B' ]What it prints (run when this page was built)