c# get random letter from string code example
Example 1: c# random string
private static Random random = new Random();
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
Example 2: random character c#
Random rnd = new Random();
int ascii_index = rnd.Next(65, 91);
char myRandomUpperCase = Convert.ToChar(ascii_index);
Random rnd2 = new Random();
int ascii_index2 = rnd2.Next(97, 123);
char myRandomLowerCase = Convert.ToChar(ascii_index2);
int i = rnd.Next(1, 3) == 1 ? rnd.Next(65, 91) : rnd.Next(97, 123);
char anyLetter = Convert.ToChar(i);