title: How to get random values from array in C#
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2019417/access-random-item-in-list">Access random item in list</a>  </p>
  </blockquote>
  
  
  
  <p>I have an array with numbers and I want to get random elements from this array.  For example: {0,1,4,6,8,2}.  I want to select 6 and put this number in another array, and the new array will have the value {6,....}. </p>
  
  <p>I use random.next(0, array.length), but this gives a random number of the length and I need the random array numbers.</p>
  
  <pre><code>for (int i = 0; i &lt; caminohormiga.Length; i++ )
  {
      if (caminohormiga[i] == 0)
      {
          continue;
      }
  
      for (int j = 0; j &lt; caminohormiga.Length; j++)
      {
          if (caminohormiga[j] == caminohormiga[i] &amp;&amp; i != j)
          {
              caminohormiga[j] = 0;
          }
      }
  }
  
  for (int i = 0; i &lt; caminohormiga.Length; i++)
  {
     int start2 = random.Next(0, caminohormiga.Length);
     Console.Write(start2);
  }
  
  return caminohormiga;
  </code></pre>