- public class RandomPasswd {
- public static String randomPasswd(int n){
- if(n<3){
- return null;
- }
-
- char[]passwd=new char[n];
- int ran=(int)(Math.random()*26);
- passwd[0]= (char) ('A'+ran);
- ran=(int)(Math.random()*26);
- passwd[1]=(char) ('a'+ran);
- ran=(int)(Math.random()*10);
- passwd[2]=(char) ('0'+ran);
- for(int i=3;i<n;i++){
-
- int rand=(int)(Math.random()*3);
- if(rand==0){
- ran=(int)(Math.random()*26);
- passwd[i]= (char) ('A'+ran);
- }
- if(rand==1){
- ran=(int)(Math.random()*26);
- passwd[i]= (char) ('a'+ran);
- }
- if(rand==2){
- ran=(int)(Math.random()*10);
- passwd[i]= (char) ('0'+ran);
- }
- }
- String randompwd= new String(passwd);
- return randompwd;
- }
-
- public static void main(String[] args) {
- System.out.println(randomPasswd(10));
- }
- }
- http://blog.csdn.net/u014082714/article/details/53162974
posted @
2016-12-22 11:10
小丑的·凡尘朽
阅读(
899)
评论()
编辑
收藏
举报