kami's notebooks

  • Roulette Bot Provably Fair Calculator - /kami/provablyfairroulettebot
    Last edited 6 years ago - from: https://npm.runkit.com/seedrandom
    //SET THIS var gamehash = "721077284eacc204ef2dbadc2c8c8f25ca9bf84a591aea7ef8e1d23e96c9dcdd"; //We're using the current game's server seed hash on ethcrash.io ///////////////// //Get the crash point from gamehash var CryptoJS = require("crypto-js") function divisible(hash, mod) { // So ABCDEFGHIJ should be chunked like AB CDEF GHIJ var val = 0; var o = hash.length % 4; for (var i = o > 0 ? o - 4 : 0; i < hash.length; i += 4) { val = ((val << 16) + parseInt(hash.substring(i, i+4), 16)) % mod; } return val === 0; } function genGameHash(serverSeed) { return CryptoJS.SHA256(serverSeed).toString() }; function hmac(key, v) { var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key); return hmacHasher.finalize(v).toString(); } function crashPointFromHash(serverSeed) { // see: provably fair seeding event var hash = hmac(serverSeed, '0x8039f1f45f2df637488cbdbb3f2eb86615a10fe96a7ce79f721355035f3adb59'); // In 1 of 101 games the game crashes instantly. if (divisible(hash, 101)) return 0; // Use the most significant 52-bit from the hash to calculate the crash point var h = parseInt(hash.slice(0,52/4),16); var e = Math.pow(2,52); return (Math.floor((100 * e - h) / (e - h))/100).toFixed(2); }; //Generate random number var crashpoint = crashPointFromHash(gamehash); var seedrandom = require("seedrandom"); var redNumbers = [1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36]; var blackNumbers = [2,4,6,8,10,11,13,15,17,20,22,24,26,28,29,31,33,35]; function getRandomInt (min, max,seed) { var rng2 = seedrandom.xor4096(seed) return Math.floor(rng2() * (max - min + 1)) + min; } var result = getRandomInt(0,38,gamehash); if(result!=0 && crashpoint != 1.97) { // 1/38 chance of landing on 0, unless crashpoint is 1.97 if(crashpoint < 1.97) result = redNumbers[getRandomInt(0,redNumbers.length-1,gamehash)]; else result = blackNumbers[getRandomInt(0,blackNumbers.length-1,gamehash)]; } else result = 0; //Voila! console.log(`The crashpoint is ${crashpoint}x`); console.log(`The roulette game result is ${result}`);