zoukankan      html  css  js  c++  java
  • C# 随机数类

    随机数类        Random            

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

        double a = ran.Next(10);            

        int b = ran.Next(s.Length);          

        Console.WriteLine(a);

    练习

                随机出验证码,对照输入,判断是否正确

                string s = "abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789";
                Random ran = new Random();
                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("输入正确!");
                }
                else
                {
                    Console.WriteLine("输入错误!");
                }
                Console.ReadLine();
                Console.Clear();
                Console.WriteLine("123");

               输入验证码

                string s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                Random ran = new Random();
                for (; ; )
                {
                    string a = "";
                    for (int i = 1; i <= 4; i++)
                    {
                        a += s.Substring(ran.Next(s.Length), 1);
                    }
    
                    Console.WriteLine(a);
    
                    Console.WriteLine("请输入验证码:");
                    string b = Console.ReadLine();
                    if (b.ToLower() == a.ToLower())
                    {
                        Console.WriteLine("输入正确");
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.WriteLine("输入错误");
                    }
                }
  • 相关阅读:
    Go语言学习笔记(3)
    Haskell语言学习笔记(97)Phantom Type
    Rust语言学习笔记(12)
    堆排序 Rust实现
    Rust 智能指针(Rc)
    Rust 泛型
    Rust 枚举
    Rust 结构体
    Rust 引用
    二叉搜索树
  • 原文地址:https://www.cnblogs.com/yy01/p/5269306.html
Copyright © 2011-2022 走看看