Advertisement
jyoung12387

Random Letters - 2 Approaches

Mar 10th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. //Approach 1
  2.  
  3. using System;
  4.  
  5. namespace RandomLetters
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Random random = new Random();
  12.  
  13.             for (int i = 0; i <10; i++)
  14.             {
  15.                 int randomLetter = random.Next(65, 91);
  16.                 Console.WriteLine((char)randomLetter);
  17.             }
  18.  
  19.             Console.ReadLine();
  20.         }
  21.     }
  22. }
  23.  
  24.  
  25. //Approach 2
  26.  
  27. using System;
  28.  
  29. namespace RandomLetters
  30. {
  31.     class Program
  32.     {
  33.         static void Main(string[] args)
  34.         {
  35.             Random random = new Random();
  36.  
  37.             // create a new array called alphabet, and assign it the value of the string alphabet.ToCharArray
  38.             char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
  39.  
  40.             for(int i = 0; i < 10; i ++)
  41.             {
  42.                 int randomLetter = random.Next(0, alphabet.Length);
  43.                 Console.WriteLine(alphabet[randomLetter]);
  44.             }
  45.  
  46.             Console.ReadLine();
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement