Created
June 10, 2025 04:38
-
-
Save xantiagoma/40d84f7cec91e1a1f4bee94f2247031b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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