1.随机取得字符串
public static String getRandomString(int length){
StringBuffer buffer=new StringBuffer("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
StringBuffer sb=new StringBuffer();
Random r=new Random();
int range=buffer.length();
for(int i=0;i<length;i++){
sb.append(buffer.charAt(r.nextInt(range)));
}
return sb.toString();
}
2.取得整形字符串
public String getRandom(int num) {
StringBuffer bf = new StringBuffer();
int a[] = new int[num];
for (int i = 0; i < a.length; i++) {
a[i] = (int) (num * (Math.random()));
bf.append(a[i]);
}
return bf.toString();
}