| // Fisher–Yates shuffle. Returns a new array; doesn't mutate the input. | |
| export function shuffle<T>(input: readonly T[]): T[] { | |
| const out = [...input]; | |
| for (let i = out.length - 1; i > 0; i--) { | |
| const j = Math.floor(Math.random() * (i + 1)); | |
| [out[i], out[j]] = [out[j], out[i]]; | |
| } | |
| return out; | |
| } | |