Files
blitzkit/packages/core/src/math/fisherYates.ts
T

8 lines
237 B
TypeScript
Raw Normal View History

2025-10-14 20:19:52 -05:00
export function fisherYates<Type extends unknown[]>(array: Type) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}