title: C# exclude numbers from a list in random generation
body: <p>I am making a tic tac toe game and I am making it to be unbeatable
  but first I have to let the computer know the rules.</p>
  
  <p>I'm stuck in a step that is => when it's the computer's turn and we have just started the game so no win case so it's up to the computer to generate a random number that will be the computer's choice ( the block where he mark X or O )
  so I need it to generate a number from 1 to 9 but by excluding the already used blocks ( numbers ).</p>
  
  <p>I tried doing that by making a list and adding a number every time the human player used a block but I can't find a way to use those numbers from the list as exclusion for the random choice of the computer.</p>
  
  <p>Here is what I tried and thnx in advance:</p>
  
  <pre><code>    //random
  
      List&lt;int&gt; cas = new List&lt;int&gt;();
      if (c1 == true)
      {
          cas.Add(1);
      }
      if (c2 == true)
      {
          cas.Add(2);
      }
      if (c3 == true)
      {
          cas.Add(3);
      }
      if (c4 == true)
      {
          cas.Add(4);
      }
      if (c5 == true)
      {
          cas.Add(5);
      }
      if (c6 == true)
      {
          cas.Add(6);
      }
      if (c7 == true)
      {
          cas.Add(7);
      }
      if (c8 == true)
      {
          cas.Add(8);
      }
      if (c9 == true)
      {
          cas.Add(9);
      }
  
  
      for (int i = 0; i &lt; cas.Count; i++)
      {
          random_except_list(cas[]);
      }
  
  public static int random_except_list(int[] x)
  {
      Random r = new Random();
      int result = r.Next(1, 9 - );
  
      for (int i = 0; i &lt; x.Length; i++)
      {
          if (result &lt; x[i])
              return result;
          result++;
      }
      return result;
  }
  </code></pre>