Skip to content

Instantly share code, notes, and snippets.

@kalm42
Created December 20, 2024 19:21
Show Gist options
  • Save kalm42/a3de9594310af6b6382074c80af81e0b to your computer and use it in GitHub Desktop.
Save kalm42/a3de9594310af6b6382074c80af81e0b to your computer and use it in GitHub Desktop.
My favorite shuffle
export function shuffle<T>(items: T[], count = 100) {
const shuffled = [...items];
for (let i = 0; i < count; i++) {
const index1 = Math.floor(Math.random() * shuffled.length);
const index2 = Math.floor(Math.random() * shuffled.length);
const temp = shuffled[index1];
shuffled[index1] = shuffled[index2];
shuffled[index2] = temp;
}
return shuffled;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment