zoukankan      html  css  js  c++  java
  • 摇奖程序和随机生成验证码

     1 //摇奖程序
     2         Random r1=new Random();
     3         Set<Integer> s=new HashSet<Integer>();
     4         while(s.size()<10)
     5         {
     6             int i1=r1.nextInt(20);
     7             if(!s.contains(i1))
     8             {
     9                 s.add(i1);
    10             }
    11         }
    12         System.out.println("从20里面随机抽取10个数:");
    13         for(int t:s)
    14         {
    15             System.out.print(" "+t);
    16         }
    17         System.out.println();
    18         //产生随机验证码
    19          String str1 = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
    20             Random yan=new Random();
    21             for(int i2=0; i2<4; i2++)
    22                  {
    23                  int j = yan.nextInt(str1.length()-1);
    24                  
    25                  String s1 = (str.substring(j, j+1));
    26                  
    27                  System.out.print(s1);
    28                  }
    29         
    View Code

  • 相关阅读:
    协程
    多进程
    多线程
    模块进阶
    内建函数
    内建属性
    属性property
    私有化
    深拷贝、浅拷贝
    ==、is
  • 原文地址:https://www.cnblogs.com/beens/p/5267976.html
Copyright © 2011-2022 走看看