PrimeDice有一个允许你滚动的脚本,它可以证明是公平的。 我对剧本很感兴趣,但它在百分之一的模具上滚动,我如何让它成为一个六面模具?
var clientSeed = "Test1";
var serverSeed =
"a72c7d6e95badadadab91d729f4eef30af2c019488bb76274290ad183";
var nonce = 1;
//----- official roll function from primedice.com
var crypto = require('crypto');
var roll = function(key, text) {
var hash = crypto.createHmac('sha512', key).update(text).digest('hex');
var index = 0;
var lucky = parseInt(hash.substring(index * 5, index * 5 + 5), 16);
while (lucky >= Math.pow(10, 6)) {
index++;
lucky = parseInt(hash.substring(index * 5, index * 5 + 5), 16); //if we reach the end of the hash, just default to highest number
if (index * 5 + 5 > 128) {
lucky = 99.99;
break;
}
}
lucky %= Math.pow(10, 4);
lucky /= Math.pow(10, 2);
return lucky;
}
console.log(roll(serverSeed, clientSeed+'-'+nonce));
答案 0 :(得分:0)
使用
return Math.ceil(((lucky+.01)/100)*6);