I'm trying to predictably shuffle javascript arrays the same way each time the webpage is loaded.
I can shuffle the arrays randomly, but every time i reload the page it's a different sequence.
I'd like it to shuffle the arrays the same way every time the page loads. There are many arrays and they are part of a procedurally generated world.
Chance.js worked perfectly. Thank you Billy Moon.
My Example:
<script type="text/javascript" src="assets/js/chance.js"></script>
var chance1 = new Chance(124); // you can choose a seed here, i chose 124
console.log(chance1.shuffle(['alpha', 'bravo', 'charlie', 'delta', 'echo']));
// Array [ "alpha", "delta", "echo", "charlie", "bravo" ]
As long as you set the seed with new Chance(xxx) you get the same result every time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With