title: Roll Multiple Dice and keep the best 3
body: <p>I am working on a Dice Roller that will roll 3 or more dice.</p>
  
  <p>What I need to do is make it so that no matter how many dice are rolled only the 3 best dice are kept.
  Here is what I have so far:
  (there is a dropdown box that has the player select the amount of dice rolled and thats what the <code>diceMethod.selectedIndex</code> is for)</p>
  
  <pre><code>function roll3d6() {
    d1=Math.floor(Math.random() * 6) + 1;
    d2=Math.floor(Math.random() * 6) + 1;
    d3=Math.floor(Math.random() * 6) + 1;
    return d1 + d2 + d3;
  }
  
  function roll4d6() {
    d1=Math.floor(Math.random() * 6) + 1;
    d2=Math.floor(Math.random() * 6) + 1;
    d3=Math.floor(Math.random() * 6) + 1;
    d4=Math.floor(Math.random() * 6) + 1;
    if ((d4&lt;=d3)&amp;(d4&lt;=d2)&amp;(d4&lt;=d1)) { return d1 + d2 + d3; }
    else if ((d3&lt;=d4)&amp;(d3&lt;=d2)&amp;(d3&lt;=d1)) { return d1 + d2 + d4; }
    else if ((d2&lt;=d4)&amp;(d2&lt;=d3)&amp;(d2&lt;=d1)) { return d1 + d3 + d4; }
    else { return d2 + d3 + d4; }
  }
  
  function roll5d6() {
    d1=Math.floor(Math.random() * 6) + 1;
    d2=Math.floor(Math.random() * 6) + 1;
    d3=Math.floor(Math.random() * 6) + 1;
    d4=Math.floor(Math.random() * 6) + 1;
    d5=Math.floor(Math.random() * 6) + 1;
    if () {
      // Run check here
    }
  }
  
  function RollTheDice(){
    // roll 3d6
    if (document.form1.diceMethod.selectedIndex === 0) {
      score1=roll3d6();
    }
    // roll 4d6 best 3
    if (document.form1.diceMethod.selectedIndex === 1) {
      score1=roll4d6();
    }
    // roll 5d6 best 3
    if (document.form1.diceMethod.selectedIndex === 2) {
      score1=roll5d6();        
    }
  }
  </code></pre>
  
  <p>My <code>roll4d6</code> works well but if possible I'd like to make it shorter, and I was hoping there was a simplified way to do the rolls so if I added more dice to the roll I wouldn't have to add to much more code to the dice check.</p>