title: Count percentages of random number occurance
body: <p>I am working on a distribution problem. For example: I want to call a function, and this function should trigger a second function. That second function can be one of 3 (three) options.  I want:
  Function A should be called 10% of the time
  Function B should be called 20% of the time
  Function C should be called 70% of the time</p>
  <p>With 2 options, (70%-30%), it is easy. I generate a random integer Math.round(Math.random()*100), then check for the result being &lt; 30. results &lt; 30 go to one function, the rest to the other and it balances out to 70/30.</p>
  <p>However, I am running into a logic problem when it comes to having more than two options.</p>
  <p>This is the outline:</p>
  <pre><code> //Initialize variables
  var twentyPercentCount = 0;
  var seventyPercentCount = 0;
  var tenPercentCount = 0;
  //Iterate 10,000 times
  for (var i = 0; i &lt; 10000; i++) {
    // generate whole integer 0-99
     // logic
  }
  console.log(&quot;number of times value is &lt; 20:  &quot; + twentyPercentCount);
  console.log(&quot;number of times value is &lt; 70:  &quot; + seventyPercentCount);
  console.log(&quot;remaining ten percent range:  &quot; + tenPercentCount);
  </code></pre>
  <p>What I am currently trying:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var twentyPercentCount = 0;
      var seventyPercentCount = 0;
      var tenPercentCount = 0;
      var distributionArray = [10, 20, 100];
      for (var i = 0; i &lt; 10000; i++) {
        var rnd = Math.round(Math.random() * 100);
        // find first element &gt; the random number
        let chosenNum = distributionArray.find((element) =&gt; element &gt;= rnd);
        if (chosenNum == 100) {
          seventyPercentCount += 1;
        } else if (chosenNum == 20) {
          twentyPercentCount += 1;
        } else {
          tenPercentCount += 1;
        }
      }
      console.log("number of values less than 10:  " + twentyPercentCount);
      console.log("number of values less than 20:  " + twentyPercentCount);
      console.log("70 percent range:  " + seventyPercentCount);</code></pre>
  </div>
  </div>
  </p>
  <p>Results</p>
  <pre><code>**number of values less than 10:  943
  number of values less than 20:  943
  70 percent range:  8025**
  </code></pre>
  <p>The problem is that the 10 and 20 percent buckets are still equal. I know this is a logic deficiency on my part, but can't get past it.</p>