I am trying to take out a random element from my array in the following 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', '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', '|', ':', };
string strng = null;
Console.WriteLine(vs.Length);
while (u <= 536870912)
{
Random random = new Random();
random.Next(0, 51);
int rndm = Convert.ToInt32(random);
strng = strng + "" + vs[rndm];
}
Console.WriteLine(strng);
so whenever i try to run it it gives me an unhandled exception, here it is:
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()
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!