string str ="abcdefghigklmnopqrstuvwxyzABCDEFJHIGKLMNOPQRSTUVWXYZ1234567890"; while(true){ string yzm = ""; Random rm = new Random(); for (int i = 0; i < 4; i++) { int index = rm.Next(0, str.Length); string x = str.Substring(index, 1); yzm += x; } Console.Write(yzm); string a = Console.ReadLine(); if(a == yzm) { break; } } Console.Read();