JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://s3.amazonaws.com/satoshi-storage/pf/sha256.js"></script>
<script src="https://s3.amazonaws.com/satoshi-storage/pf/MersenneTwister19937.js"></script>
<div id="result"></div>
JavaScript
var clientSeed = "7d12b0c212717696298ddb53f3d6910a230d2b582d2a20e893121e9118bb78a9";
var serverSeed = "4048ff404b974156c713ea0055eaad5d9fe94fadd477b95ab3a0240d5ac9bd2c";
var initialShuffleArray = [1,1,1,1,1,4,2,2,2];
// Shuffles an array using the Fisher-Yates shuffle algorithm.
var fisherYatesShuffle = function (collection, mt) {
var r;
for (var i = collection.length - 1; i > 0; i--) {
r = mt.genrand_int32() % (i + 1);
tmp = collection[r];
collection[r] = collection[i];
collection[i] = tmp;
}
return collection;
}
var validations = {};
// Hash `clientSeed` and `serverSeed`.
var seedString = CryptoJS.SHA256(clientSeed + serverSeed).toString();
// Take the bottom 32 bits of the hash to use as the seed for the RNG.
var seed = parseInt(seedString.substring(seedString.length - 8), 16);
var mt = new MersenneTwister19937();
mt.init_genrand(seed);
// Verify that the initial number matches `final_shuffle`.
var reshuffled = fisherYatesShuffle(initialShuffleArray, mt);
console.log(reshuffled);
document.getElementById("result").innerHTML = JSON.stringify(reshuffled);