Reference · Framing, geometry and quiz tools
shuffledfunction
A copy of the list in a random order (Fisher–Yates, from the end); the list given is left alone.
Import it
import { shuffled } from "@johnmorrisdotca/chizu";
Definition
function shuffled<T>(items: readonly T[], random: Random): T[]
Parameters
| Name | Type | Description |
|---|---|---|
items | readonly T[] | The input items; shuffling returns a copy. |
random | Random | A random source returning a value in [0, 1); use seededRandom for reproducible output. |
Returns
T[]
A copy of the list in a random order (Fisher–Yates, from the end); the list given is left alone.
Examples
import { seededRandom, shuffled } from "@johnmorrisdotca/chizu";
const items = ["JP", "FR", "BR", "EG"];
console.log(shuffled(items, seededRandom(7)).join(" ") === shuffled(items, seededRandom(7)).join(" "), items.join(" "));
// true JP FR BR EGtrue JP FR BR EGWhat it prints (run when this page was built)