當前位置:名人名言大全網 - 短信平臺 - java如何隨機生成6位數的驗證碼

java如何隨機生成6位數的驗證碼

public static final char[] chars={'1','2','3','4','5','6','7','8','9','0','Q','W','E','R','T','Y','U','I','O',

'P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M'};

public static Random random=new Random();

public static String getRandomString(){

StringBuffer sb=new StringBuffer();

for(int i=0;i<=5;i++){

sb.append(chars[random.nextInt(chars.length)]);;

}

return sb.toString();

}