title: for loop, Math.random() not acting as intended
body: <p>I'm trying to code a dice game in javascript, using Math.random() to generate the values of the dice and an array to hold the current values of each individual die.</p>
  
  <p>The problems I'm having are 1), the array ends up containing six numbers, and the loop only runs five times, and 2) I can't figure out how to get Math.random() to return different numbers on each dice roll.</p>
  
  <p>Here's the function in question:</p>
  
  <pre><code>var array = []
  
  function rollDice() {
      for (var i = 0; i &lt;= 4; i++) {
  
          var roll = Math.floor(Math.random() * 6) + 1;
  
          array[i] = roll;
          //array.splice(i, 1, roll);
      }
  }
  </code></pre>
  
  <p>You can see that 'i' iterates from zero to four in the loop (which equals five loops), and on each loop another random number is generated and inserted into the array at the equivalent place.</p>
  
  <p>Regarding the number of items in the array: if I run the code as written above, I'll get something like this: [1, 2, 3, 4, 5, undefined].
  If I run it using the commented line with the 'splice' function (which should remove the value stored at place 'i' and replace it with a new value,) I'll get [1, 2, 3, 4, 5, 6]. How is this happening if the loop is only running five times?</p>
  
  <p>As to the difficulty I'm having getting the random numbers to change more reliably: I've tried the following in my loop...</p>
  
  <pre><code>var roll;
  while (roll === hand[i] || roll === null) {
      roll = Math.floor(Math.random() * 6) + 1;
  }
  </code></pre>
  
  <p>...in the hopes that 'roll' will keep spinning random numbers until it comes up with a different one, but no dice. Does anyone have any suggestions?</p>
  
  <p>EDIT: I've added an explicit array declaration since I didn't make it clear enough that my array was in fact being explicitly declared before. </p>