title: Properly implementing C#'s random number generator
body: <p>I'm trying to generate two random numbers, one for a row and one for a column.</p>
  
  <p>In this exact instance, it is a multidimensional array with 4 rows and 4 columns. Thus, the number generator can use the values 0 to 3 for both row and column.</p>
  
  <p>I must also make sure that there are no duplicate points, so if [0,0] is chosen the first time, [0,0] can not be used again.</p>
  
  <p>When I implement my solution and print out the results, it takes a <em>LONG</em> time for C# to generate a working set of numbers.</p>
  
  <p>For instance, I am only looking for 10 numbers out of 16 possibilities in this case and this is what the output looked like:</p>
  
  <pre><code>[1,1]
  // {snip 26 times}
  [3,3]
  // {snip 76 times}
  [0,0]
  // {snip 83 times}
  [2,2]
  // {snip 69 times}
  [0,0]
  // {snip 84 times}
  // {etc...}
  [0,1] // which is a valid number
  </code></pre>
  
  <p>Why is it finding [0,0] as a set of random numbers 84 times in a row? Does it not use my system's local entropy or what?</p>
  
  <p>Here is the relevant code:</p>
  
  <pre><code>private static void RandomlyAssignSeat(string name, string[,] seatingArray)
  {
      int row, col;
  
      // loop until seat is not reserved, then reserve it
      do
      {
          // generate random row
          row = RandomNumber(0,seatingArray.GetLength(0));
  
          // generate random column
          col = RandomNumber(0,seatingArray.GetLength(1));
  
          Console.WriteLine("[" + row + "," + col + "]");
      } while (ReserveSeat(row, col, name, seatingArray) == false);
  } // end method RandomlyAssignSeat
  </code></pre>
  
  <p>with RandomNumber looking like so:</p>
  
  <pre><code>private static int RandomNumber(int min, int max)
  {
      Random random = new Random();
      return random.Next(min, max);
  } // end method RandomNumber
  </code></pre>
  
  <p>I find it gets especially choked up with 90 records with a maximum array of 16x6 (or 96 records)</p>