Skip to content

Instantly share code, notes, and snippets.

@quocble
Last active July 9, 2019 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quocble/0f61553c24c1f43a8c6d2d12486f90fa to your computer and use it in GitHub Desktop.
Save quocble/0f61553c24c1f43a8c6d2d12486f90fa to your computer and use it in GitHub Desktop.
const serverHash = "d280d20edc8da0944f9893fe4e8e3b2010d197ef19f83856ebdd930866d54d04";
const clientSeed = "732d81dc27d5fa9d";
var nonce = 3000;
const roll_prime_dice = function (key, text) {
// create HMAC using server seed as key and client seed as message
const hash = crypto
.createHmac('sha512', key)
.update(text)
.digest('hex');
let index = 0;
const j = 5;
let lucky = parseInt(hash.substring(index * j, index * j + j), 16);
// keep grabbing characters from the hash while greater than
while (lucky >= Math.pow(10, 6)) {
index++;
lucky = parseInt(hash.substring(index * j, index * j + j), 16);
// if we reach the end of the hash, just default to highest number
if (index * 5 + 5 > 128) {
lucky = 9999;
break;
}
}
// commented out to get the largest possible value.
//lucky %= Math.pow(10, 4);
//lucky /= Math.pow(10, 2);
return lucky;
};
function generate(count) {
var out = []
for (var i=0; i < count; i++) {
const e = jsData[Math.floor(Math.random()*500)]
const str = e.blocksig + "" + e.tx + "0";
// var buffer = createHash("sha256").update(str).digest()
const n = roll_prime_dice(serverHash, `${clientSeed}-${nonce}`)
//var n = randomN2(chainId, buffer, 0, Math.pow(2,32))
nonce++;
out.push(n)
}
return out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment