[java] view plain cop

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34161388/article/details/78720044

[java] view plain cop

  1. public String genRandomNum(){  
  2.       int  maxNum = 36;  
  3.       int i;  
  4.       int count = 0;  
  5.       char[] str = { 'A''B''C''D''E''F''G''H''I''J''K',  
  6.         'L''M''N''O''P''Q''R''S''T''U''V''W',  
  7.         'X''Y''Z''0''1''2''3''4''5''6''7''8''9' ,'=','+',};      
  8.       StringBuffer pwd = new StringBuffer("");  
  9.       Random r = new Random();  
  10.       while(count < 8){  
  11.        i = Math.abs(r.nextInt(maxNum));     
  12.        if (i >= 0 && i < str.length) {  
  13.         pwd.append(str[i]);  
  14.         count ++;  
  15.        }  
  16.       }  
  17.       return pwd.toString();  
  18.     }  
[java]  view plain  copy
  1. 该方法加形参,可以改造为生成任意位数的随机字符串 
  1. public String genRandomNum(){  
  2.       int  maxNum = 36;  
  3.       int i;  
  4.       int count = 0;  
  5.       char[] str = { 'A''B''C''D''E''F''G''H''I''J''K',  
  6.         'L''M''N''O''P''Q''R''S''T''U''V''W',  
  7.         'X''Y''Z''0''1''2''3''4''5''6''7''8''9' ,'=','+',};      
  8.       StringBuffer pwd = new StringBuffer("");  
  9.       Random r = new Random();  
  10.       while(count < 8){  
  11.        i = Math.abs(r.nextInt(maxNum));     
  12.        if (i >= 0 && i < str.length) {  
  13.         pwd.append(str[i]);  
  14.         count ++;  
  15.        }  
  16.       }  
  17.       return pwd.toString();  
  18.     }  
[java]  view plain  copy
  1. 该方法加形参,可以改造为生成任意位数的随机字符串 

猜你喜欢

转载自blog.csdn.net/qq_34161388/article/details/78720044