Created
December 24, 2019 19:46
-
-
Save nkgokul/72577c8e0472aa8eb8b7b5722d76ed83 to your computer and use it in GitHub Desktop.
Check rnadom function distribution
This file contains hidden or 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
function checkUniformDistributionOfRandom(percentateOfErrorsToLog = 10) { | |
const percentateOfErrorsToLogFraction = percentateOfErrorsToLog/100; | |
const threshold = 1 - percentateOfErrorsToLogFraction; | |
const numberOfLoops = 1000; | |
for (let i=1; i<numberOfLoops; i++){ | |
if (Math.random() >= threshold) console.log("This should be printed " + percentateOfErrorsToLogFraction * numberOfLoops + " times"); | |
} | |
} | |
[10, 20, 30, 40, 50, 60, 70, 80, 90].map(checkUniformDistributionOfRandom); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment