Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Program
- {
- static Random random = new Random();
- public static List<char> charList = new List<char> {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
- 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
- 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3',
- '4', '5', '6', '7', '8', '9'};
- public static void Main()
- {
- //Display output of 10 random codes
- for(int i = 0; i <10; i++)
- {
- DisplayCode(GetCode());
- }
- }
- // Generate random 16 char string from the charList list
- public static string GetCode()
- {
- string output = "";
- for(int i = 0; i<16; i++)
- {
- int charIndex = random.Next(charList.Count);
- output += charList[charIndex];
- }
- return output;
- }
- // Format string with "-" every 4 chars
- public static void DisplayCode(string code)
- {
- code = code.Insert(12,"-");
- code = code.Insert(8,"-");
- code = code.Insert(4,"-");
- Console.WriteLine(code);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement