Last active
October 25, 2021 02:31
-
-
Save zaneclaes/7c8167aad9062d7442f062dbc8faeaec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function testDice(func, bytes = 2, runs = 1000) { | |
let sequence = ''; | |
const vals = []; | |
let last = 0; | |
for (let i=0; i<runs; i++) { | |
last = await func(i, last); | |
let hex = last.toString(16); | |
while (hex.length < (bytes * 2)) hex = `0${hex}`; | |
for (let b=0; b<(bytes*2); b++) { | |
const h = hex.substr(b, 1); | |
const iv = parseInt(h, 16); | |
let bin = (iv >>> 0).toString(2); | |
while (bin.length < 4) bin = `0${bin}`; | |
sequence += bin; | |
} | |
vals.push(last); | |
const numMine = Math.floor(Math.random() * 10 + 2); | |
for (let i=0; i<numMine; i++) { | |
await ethers.provider.send("evm_mine"); | |
} | |
} | |
const r = new RandomTests(sequence); | |
const res = { | |
bits: sequence.length, | |
monobit: randomness.monobitTest(sequence), | |
frequency: analyzeTest(r.frequencyTest()), | |
longestRunOfOnes: analyzeTest(r.longestRunOfOnesTest()), | |
}; | |
console.log(res); | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment