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
const { random, floor } = Math; | |
function tryit() { | |
let count = 0; | |
while (true) { | |
++count; | |
if (random() < 1 / (2000 - count)) { | |
return count; | |
} | |
} | |
} | |
let data = []; | |
for (let ii = 0; ii < 10000; ++ii) { | |
let num_rolls = tryit(); | |
let bucket = floor(num_rolls / 200); | |
data[bucket] = (data[bucket] || 0) + 1; | |
} | |
for (let ii = 0; ii < data.length; ++ii) { | |
console.log(`${ii*200}-${(ii+1)*200}: ${data[ii] || 0}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment