Hi,
How can I pick a random Alphabet Characters?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Mar 19, 2014, 9:08 AM
using System;
class Test
{
static Random r = new Random();
static void Main()
{
// generate 10 random letters
for(int i = 0; i < 10; i++)
{
char c = GetRandomChar();
Console.Write(c);
}
Console.ReadKey();
}
static char GetRandomChar()
{
int c = r.Next(26);
return (char)(97 + c);
}
}
Abhay ShankerPosted Mar 19, 2014, 9:23 AM
using System;
static class RandomLetter
{
static Random _random = new Random();
public static char GetLetter()
{
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());
}
}