title: Javascript - generating random pairs of numbers if pair doesn't already exist
body: <p>Edit: If you read Matt Bryant's answer, you'll see that it should work but he uses indexOf() method and that method doesn't work with I.E 8 or later and I need it to work on I.E 8. I tried doing this as a work around to the indexOf() method but it's not working.</p>
  
  <pre><code>var tester = -1;
  for (var test=0; test&lt;xposition.length; test++) {
      if (x == xposition[0]) {
          tseter = x;
      }
  }
  </code></pre>
  
  <p>Any idea why it doesn't work?</p>
  
  <p>Original question: 
  So I want to generate random pairs of numbers but only if the pairs of number didn't already be generated. Here is what I tried, hopefully if you read what I tried, you will understand what it is exactly which I need.</p>
  
  <pre><code>function randomPairs() {
      var xposition = []; //array which holds all x coordinates
      var yposition = []; //array which holds all y coordinates
      for (var i=0; i&lt;5; i++) { //do everything below 5 times (generate 5 pairs)
  
          var x = getRandom(1,7); //generate new x point
          var y = getRandom(2,7); //generate new y point
  
          if ( jQuery.inArray(x, xposition) ) { //if newly generated x point is already in the xposition array (if it was already previously generated
               var location = xposition.indexOf(x) //find the index of the existing x
  
               if (y == yposition[location]) { //if the newly generated y points equals the same y point in the same location as x, except in the yposition array
  
                   while ( y == yposition[location]) {
                       y = getRandom(2, 7); //change y
                   }
               }
         }
    }
    xposition.push(x); //put x into the array
    yposition.push(y); //put y into the array
  }
  </code></pre>
  
  <p>So, any idea why it isn't working? Am I using the jQuery.inArray() and the .indexOf() method properly?</p>
  
  <p>Oh, and getRandom is </p>
  
  <pre><code>function getRandom(min, max) {
      return min + Math.floor(Math.random() * (max - min + 1));
  }
  </code></pre>
  
  <p>basically, it generates a number between the min and max.</p>
  
  <p>Also, when I tried to do</p>
  
  <pre><code>alert(xposition);
  alert(yposition);
  </code></pre>
  
  <p>it is blank.</p>