feat(tools): add get_random_words tool with Fisher-Yates shuffle

This commit is contained in:
2026-02-21 18:42:28 -06:00
parent a51842c48f
commit 03edd6e9d1
4 changed files with 54 additions and 0 deletions

11
helpers/shuffle.ts Normal file
View File

@@ -0,0 +1,11 @@
const fishersYatesShuffle = <Type>(arr: Type[]): Type[] => {
const shuffled = [...arr]
for (let index = shuffled.length - 1; index > 0; index--) {
const secondIndex = Math.floor(Math.random() * (index + 1))
// biome-ignore lint/style/noNonNullAssertion: indices are guaranteed to be valid in Fisher-Yates shuffle
;[shuffled[index]!, shuffled[secondIndex]!] = [shuffled[secondIndex]!, shuffled[index]!]
}
return shuffled
}
export default fishersYatesShuffle