title: Run JavaScript function 70% of the time, randomly selected from an array of functions
body: <p>I've seen <a href="https://stackoverflow.com/questions/10693488/how-to-run-a-randomly-selected-function-in-javascript">How to run a randomly selected function in JavaScript?</a> which allows for running a JavaScript function randomly selected from at array with an equal chance each time (e.g. if there are two functions in total, there is a 50% chance that each function will be executed each time).</p>
  
  <p>How to write a function to state the percentage chance of executing each function that is randomly available to be chosen from an array of functions? <strong>How do I do a weighted randomization??</strong></p>
  
  <pre><code>function randomFrom(array) {
      return array[Math.floor(Math.random() * array.length)];
  }
  var contentWrapper = function (target,type,articleId) {
    // list type ads
    if (type == 'list') {
      function randomListData() {
        var func = randomFrom([
          function () {
            fnNameA10(target, 'list');
          },
          function () {
            fnNameB20(target, 'list', articleId);
          }
        ]);
        (func)();
      }
      randomListData();
      // content type ads
    } else if (type == 'content') {
      function randomContentData() {
        var func = randomFrom([
          function () {
            fnNameA10(target, 'content');
          },
          function () {
            fnNameB20(target, 'content', articleId);
          }
        ]);
        (func)();
      }
      randomContentAd();
    }
  };
  </code></pre>