title: how to take a random element out of an array in C#
body: <p>I am trying to take out a random element from my array in the following code:</p>
  <pre><code>                char[] vs = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '~', '!', '@', '#', '$', '%', '^', '&amp;', '*', '(', ')', '-', '_', '+', '=', '|', ':', };
                  string strng = null;
  
                  Console.WriteLine(vs.Length);
                  while (u &lt;= 536870912)
                  {
                      Random random = new Random();
                      random.Next(0, 51);
                      int rndm = Convert.ToInt32(random);
                      strng = strng + &quot;&quot; + vs[rndm];
  
                  }
                  Console.WriteLine(strng);
  </code></pre>
  <p>so whenever i try to run it it gives me an unhandled exception, here it is:</p>
  <pre><code>52
  System.InvalidCastException: Unable to cast object of type 'System.Random' to type 'System.IConvertible'.
     at System.Convert.ToInt32(Object value)
     at ConsoleApp1.Program.Main()
  </code></pre>
  <p>the main purpose of the whole code is to generate random characters from the array, as long as it's less than 512 megabytes (which can be noticed in the code), if you have any idea please help me figure this out, thanks!</p>