title: How to select a random element from an array with two variables
body: <p>I have created a program and I would like to select a random element from an array, however I need to make sure that that element is not of a certain type. To show what type it is, when i created the array i assigned 3 numbers. 0=normal human, 1=Zombie, 2= cat. The array initially spawns a 10 * 10 array of normal humans however when you right click you can spawn a zombie. The function then runs when the play hits a start button(info on function not needed for question). If no zombie is selected i want it to create a random one from a human. This is the code so far:</p>
  
  <pre><code>    for (int x = 0; x &lt; 10; x++) {
              for (int y = 0; y &lt; 10; y++) {
                  if (canZombSpawn == false) {
                      ZombieSpreader(playingGrid[x][y].face, playingGrid[x][y].typeOfChar);
                  } else {
                      do {
                          t = (int) ((Math.random() * 10));
                          p = (int) ((Math.random() * 10));
  
                      } while (playingGrid[t][p].typeOfChar != 0);
                      image = new ImageIcon("zombie.gif");
                      playingGrid[t][p].face.setIcon(image);
                      playingGrid[t][p].typeOfChar = 1;
                      ZombieSpreader(playingGrid[x][y].face, playingGrid[x][y].typeOfChar);
                  }
              }
          }
  </code></pre>
  
  <p><code>ZombieSpreader</code> is the method (not important)</p>
  
  <p><code>playingGrid</code> is the array and <code>typeOfChar</code> is the type of character.</p>
  
  <p>Any help is much appreciated thanks =)</p>