3月12日 随机数类 Random

Random:

Random ran=new Random();//初始化

int a=ran.Next(10);

Console.WhiteLine(a);

Console.ReadLine();

//随机出验证码,对照输入,判断是否正确;            
            string s = "abcdefghijklmnopqistuvwxyzABCDEFGHIJKLMNOPQISTUVWXYZ0123456789";
            Random ran = new Random();
            for (; ; )
            {
                string biao = "";
                for (int i = 1; i <= 4; i++)
                {
                    biao += s.Substring(ran.Next(s.Length), 1);
                }
                Console.WriteLine(biao);
                Console.Write("请输入验证码:");
                string shu = Console.ReadLine();
                if (shu.ToLower() == biao.ToLower())
                {
                    Console.WriteLine("输入正确");
                    break;
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("输入错误!");

                }
            }
            Console.ReadLine();
原文地址:https://www.cnblogs.com/dongqiaozhi/p/5268260.html