a moon tracking bot for Bluesky
at main 15 lines 479 B view raw
1export function getRandomElement<T>(arr: readonly T[]): T { 2 if (arr.length === 0) { 3 throw new Error("Cannot get random element from empty array"); 4 } 5 return arr[Math.floor(Math.random() * arr.length)]; 6} 7 8export function shuffleArray<T>(arr: T[]): T[] { 9 const shuffled = [...arr]; 10 for (let i = shuffled.length - 1; i > 0; i--) { 11 const j = Math.floor(Math.random() * (i + 1)); 12 [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; 13 } 14 return shuffled; 15}