title: Filling up a 2D array with random numbers in javascript
body: <p>I'm really sorry if anything like this has been posted here before but I couldn't find anything, I'm kinda new to the site still!  </p>
  
  <p>So for a while now I've been learning a bit about game development through html5 and javascript and I stumbled upon making tileset maps, I now have a tileset and an 2D array that I want to put certain tiles in (the number varies between 6 and 10 in this case).
  I figured it could be a cool function to make the map choose between a small set of similar tiles so I don't have to specifically number every tile in the array(just define the type)</p>
  
  <p>The method I have currently is probably the best for being able to define types but I want something that looks a bit cleaner and/or information to why my "cleaner" version dosen't work.</p>
  
  <pre><code>var ground = [
      [tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile()],
      [tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile()],
      [tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile()],
      [tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile()],
      [tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile()],
      [tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile()],
      [tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile()],
      [tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile()],
      [tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile(),tile()]];
  
  function tile() {
      var y = (Math.random() * 5 | 0) + 6;
      return y;
  }
  </code></pre>
  
  <p>This is the code I've been using so far, I have to edit every element of the code with the tile() function to get a random number in each one, what I wanted to have was something like this:</p>
  
  <pre><code>for (var i = 0 ; i &lt; 15; i++) {
      for (var j = 0; j &lt; 9; j++) {
          ground[[i],[j]] = (Math.random() * 5 | 0) + 6;
      }
  }
  </code></pre>
  
  <p>to fill the array without having to add the function to each spot.</p>
  
  <p>I have a feeling that I'm missing a return function or something along those lines but honestly I have no idea.</p>