版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34161388/article/details/78720044
[java] view plain cop
- public String genRandomNum(){
- int maxNum = 36;
- int i;
- int count = 0;
- char[] str = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
- 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
- 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ,'=','+',};
- StringBuffer pwd = new StringBuffer("");
- Random r = new Random();
- while(count < 8){
- i = Math.abs(r.nextInt(maxNum));
- if (i >= 0 && i < str.length) {
- pwd.append(str[i]);
- count ++;
- }
- }
- return pwd.toString();
- }
- 该方法加形参,可以改造为生成任意位数的随机字符串
- public String genRandomNum(){
- int maxNum = 36;
- int i;
- int count = 0;
- char[] str = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
- 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
- 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ,'=','+',};
- StringBuffer pwd = new StringBuffer("");
- Random r = new Random();
- while(count < 8){
- i = Math.abs(r.nextInt(maxNum));
- if (i >= 0 && i < str.length) {
- pwd.append(str[i]);
- count ++;
- }
- }
- return pwd.toString();
- }
- 该方法加形参,可以改造为生成任意位数的随机字符串