java 生成15位的随机码

import java.util.ArrayList;
import java.util.List;

public class GeneratePswd {

@SuppressWarnings({ "unchecked", "unchecked" })
public static void main(String[] args) {

StringBuffer buf = new StringBuffer(
"a,b,c,d,e,f,g,h,i,g,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z");
buf.append(
",A,B,C,D,E,F,G,H,I,G,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z");
buf.append(
",~,@,#,$,%,^,&,*,(,),_,+,|,`,.");
buf.append(
",1,2,3,4,5,6,7,8,9,0");

String[] arr = buf.toString().split(
",");
List pswdList = new ArrayList();

for(int i=0;i<50;i++){
pswdList.add(getPswd(arr));
}

for(int i=0;i<pswdList.size();i++){
System.out.println(pswdList.get(i));
}
}

public static String getPswd(String[] arr){
StringBuffer b = new StringBuffer();
java.util.Random r;
int k ;
for(int i=0;i<15;i++){
r = new java.util.Random();
k = r.nextInt();
b.append(String.valueOf(arr[Math.abs(k % 76)]));
}

return b.toString();
}

}


参考资料
lunzi   2009-02-11 11:23:03 评论:1   阅读:2529   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

认证码: (如不清楚,请刷新)


Copyright@2004-2010 powered by YuLog