例题:随机生成验证码。Random a=New Random(), 重点随机数格式 .Next , Substring

static void Main(string[] args)
        {
            string sj = "abcdefghijklmnopqrstuvwxyz";
            while (true)
            {
                Random r = new Random();  //定义随机数,固定格式
                string s1 = sj.Substring(r.Next(0, 26), 1); //r.next随机抽取一个数,然后向后截取一位
                string s2 = sj.Substring(r.Next (0,26),1);
                string s3 = sj.Substring(r.Next(0, 26), 1);
                string s4 = sj.Substring(r.Next(0, 26), 1);
                Console.WriteLine(s1+s2+s3+s4);
                Console.ReadLine();

posted @ 2015-04-14 23:07  zhenximeiyitian  阅读(288)  评论(0)    收藏  举报