成功捷径,贵在坚持
人为善,福虽未至祸已远离; 人为恶,祸虽未至福已远离

import java.util.Random;

/**
 *  <p>@Description:</p>
 *  <p>@Company:     上海###########公司</p>
 *  <p>@CreateDate:  2006-4-19</p>
 *     @author:      zyk
 *    @version:     1.0 
 */

public class GenerateRandomPassword {
 
 //密码生成字符
 public static String PASSWORDCHAR[]=new String[]{"0","1","2","3","4","5","6","7","8","9",
  "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",
  "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"
 };
 
 //生成密码的位数
 public static int LENGTH=6;
 
 /**
  * @Function:<p> 生成密码随机数</p>
  * @param str  获取生成密码的字符
  * @param len  控制生成密码的位数
  * @return
  * @author zyk
  * @CREATEDATE 2006-4-19 
  */
 public static String getRandom(String str[],int len){
  String temp="";
  int rand;
  Random random = new Random();
  //random.setSeed(str.length);
  for(int i=0;i<len;i++){
   rand=random.nextInt(str.length);      
   temp+=str[rand];
  }
  return temp;
 }
}

posted on 2006-05-09 17:35 选宝网an9 阅读(370) 评论(1)  编辑  收藏 所属分类: java

FeedBack:
# re: 产生随机密码
2007-10-23 17:34 | gembin
good  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: