This post will discuss how to generate a random character in C#.

The Random.Next() method generates a pseudo-random value between the specified range. You can use it to generate a random character from a specified string. The idea is to generate a random number between 0 and the string’s length, and return the character at the generated random index from the string. In C#, this translates to:

Download  Run Code

 
Alternatively, if you need to generate a random character from the specified subset of characters, you can do like below. The solution the random character from range consisting of ASCII alphabets.

Download  Run Code

That’s all about generating a random character in C#.