Skip to content

Instantly share code, notes, and snippets.

@nkgokul
Created December 24, 2019 19:46
Show Gist options
  • Select an option

  • Save nkgokul/72577c8e0472aa8eb8b7b5722d76ed83 to your computer and use it in GitHub Desktop.

Select an option

Save nkgokul/72577c8e0472aa8eb8b7b5722d76ed83 to your computer and use it in GitHub Desktop.

Revisions

  1. nkgokul created this gist Dec 24, 2019.
    10 changes: 10 additions & 0 deletions check_rand_function_distribution.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    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);