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