sindresorhus / array-shuffle

Randomize the order of items in an array
MIT License
107 stars 11 forks source link

Feature Request: add seed-based shuffling #5

Open mesqueeb opened 3 years ago

mesqueeb commented 3 years ago

I'd love to be able to set a seed to then shuffle an array. Where given the same seed, the result of the shuffle will always return the same result.

FredrikAugust commented 3 years ago

Might be hard without introducing a lot of new code as JS doesn't support seeding its PRNG. You could use a package like davidbau/seedrandom as the PRNG in the shuffle, but then you would introduce a package dependency into the project which might not be desirable (based on the fact that there are no deps now, and package lock is disabled in npmrc).

The easiest might be to fork the project and adding the seedable PRNG or copying the index.js file into your own project and modifying it there.

sindresorhus commented 3 years ago

I think we can make it more general and just add an option to provide your own random number generator function. That way you can use whatever seedable random number generator you want.

sindresorhus commented 3 years ago

At some point, maybe JS will have seeded random built-in and then we could add a specific seed option: https://github.com/tc39/proposal-seeded-random