Skip to content

Instantly share code, notes, and snippets.

@nkgokul
Created December 24, 2019 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkgokul/72577c8e0472aa8eb8b7b5722d76ed83 to your computer and use it in GitHub Desktop.
Save nkgokul/72577c8e0472aa8eb8b7b5722d76ed83 to your computer and use it in GitHub Desktop.
Check rnadom function distribution
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