This commit is contained in:
Gavin McDonald
2025-04-12 15:17:02 -04:00
parent 1734eec436
commit 6508d40b2d
19 changed files with 1415 additions and 1344 deletions

View File

@@ -1,11 +1,11 @@
export default function getRandomItems<T>(items: T[], count: number): T[] {
const shuffled = [...items];
const shuffled = [...items];
// Fisher-Yates shuffle
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
// Fisher-Yates shuffle
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return count > shuffled.length ? shuffled : shuffled.slice(0, count);
}
return count > shuffled.length ? shuffled : shuffled.slice(0, count);
}