
You want to generate a random lowercase letter, between 'a' and 'z' inclusive, using the C# programming language. Random character generation can be accomplished by providing inclusive and exclusive bounds to the Random variable.
This C# article shows how you can generate a random stream of lowercase letters.

First we look at a program text that introduces two classes to the compilation unit. The RandomLetter class is a static class, meaning it cannot be instantiated; the Program class contains the Main entry point. The GetLetter static method on the RandomLetter type provides a way to get the next random letter.
Program that generates random lowercase letter [C#]
using System;
static class RandomLetter
{
static Random _random = new Random();
public static char GetLetter()
{
// This method returns a random lowercase letter.
// ... Between 'a' and 'z' inclusize.
int num = _random.Next(0, 26); // Zero to 25
char let = (char)('a' + num);
return let;
}
}
class Program
{
static void Main()
{
// Get random lowercase letters.
Console.WriteLine(RandomLetter.GetLetter());
Console.WriteLine(RandomLetter.GetLetter());
Console.WriteLine(RandomLetter.GetLetter());
Console.WriteLine(RandomLetter.GetLetter());
Console.WriteLine(RandomLetter.GetLetter());
}
}
Output
i
q
f
t
oOverview. The GetLetter public static parameterless method provides a way to get another random letter. It internally references the static field Random variable. It calls the Next parameterful instance method and stores the result of that onto the evaluation stack as an integer local variable. It then uses type conversion to convert the value of 0-25 to the letters 'a'-'z'. This is possible because the range of letters 'a'-'z' is exactly 'a' places past zero.

Random fields. When using the Random variable type, it is often useful to store the Random variable itself as a static field. This is because, logically, Random implements a stream of randomness, not true randomness.
Random Number
We examined a program text that implements a random letter generation routine. The method shown returns a random letter between 'a' and 'z' in char representation; it can be called sequentially as it is implemented as a random stream. The static modifier is used here to simplify the program layout and reduce instantiations.
Algorithms