首页 > 其他 > 详细

摇奖程序和随机生成验证码

时间:2016-03-12 10:22:30      阅读:116      评论:0      收藏:0      [点我收藏+]
技术分享
 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

技术分享

摇奖程序和随机生成验证码

原文:http://www.cnblogs.com/beens/p/5267976.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!