How do you create a random letter in C#?

Updated 17 hours ago in Challenges
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
4 on November 28, 2017

I am vary new to coding and and I am using C#. I was able to make a line of code that asks you random math questions. I have tried but due to my currently limited knowledge I am not sure how to make the switch from random numbers to random Letters

  • Liked by
Reply
3 on November 29, 2017

What do you mean by random letters?

on November 29, 2017

Like if I were trying to learn Morse code. It would say:

What is Morse code for: (random letter)

I am not sure how I would set that up in the code. Would I want to assign the letters of the alphabet to integers then call on those integers randomly?  

on December 1, 2017

Like this maybe? 

 string[] alphabet = new string[9] { "a", "b", "d", "e", "f", "g", "h", "i", "j" };
 Random ran = new Random();
 string randomLetter = alphabet[ran.Next(0,alphabet.Length)];
 Console.WriteLine(randomLetter);
 Console.ReadLine();

edit: Although, you could/should probably use char instead of string

17 hours ago

You can make something like that to have all the alphabet

char myChar = 'a';
 Random ran = new Random();
 myChar += (char)ran.Next(0, 26);
 Console.Write(myChar);
Show more replies
  • Liked by
Reply
Cancel