/** * Fisher-Yates shuffle algorithm, based on these answers: * https://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array */ export function shuffle(arr: T[]): T[] { let ret = [...arr]; for (let i = ret.length - 1; i >= 0; i--) { const j = Math.floor(Math.random() * (i + 1)); if (i === j) continue; const x = ret[i]!; ret[i] = ret[j]!; ret[j] = x; } return ret; }