您的位置:首页 > 其它

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

2016-03-12 10:03 399 查看
//摇奖程序
Random r1=new Random();
Set<Integer> s=new HashSet<Integer>();
while(s.size()<10)
{
int i1=r1.nextInt(20);
if(!s.contains(i1))
{
s.add(i1);
}
}
System.out.println("从20里面随机抽取10个数:");
for(int t:s)
{
System.out.print(" "+t);
}
System.out.println();
//产生随机验证码
String str1 = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
Random yan=new Random();
for(int i2=0; i2<4; i2++)
{
int j = yan.nextInt(str1.length()-1);

String s1 = (str.substring(j, j+1));

System.out.print(s1);
}


View Code

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: