Skip to content

Instantly share code, notes, and snippets.

@xantiagoma
Created June 10, 2025 04:38
Show Gist options
  • Save xantiagoma/40d84f7cec91e1a1f4bee94f2247031b to your computer and use it in GitHub Desktop.
Save xantiagoma/40d84f7cec91e1a1f4bee94f2247031b to your computer and use it in GitHub Desktop.
import seedrandom from 'seedrandom';
export function shuffleArray<T>(array: T[], seed: string): T[] {
const rng = seedrandom(seed); // Create a seeded random generator
const shuffledArray = array.slice(); // Create a copy of the array
// Fisher-Yates shuffle using the seeded random function
for (let i = shuffledArray.length - 1; i > 0; i--) {
const j = Math.floor(rng() * (i + 1));
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
}
return shuffledArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment