java隨機生成密碼(大小寫數字)

package com.liang.password.util;

import java.util.Random;

public class CreatePasswordUtil {
	public static int seed = 0;
	static final char[] PASSWORD_CHAR = { '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', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
	
    /**
     * 
     * @Description:
     * @param 
     * @return 
     *
     */
	public static String cretePassword(int psLen){
		
		int rdGet = 0;
		StringBuffer passwordSB = new StringBuffer();
		
		Random random = new Random(seed);
		int count = 0;
		while(count < psLen){
			rdGet = Math.abs(random.nextInt(PASSWORD_CHAR.length));
			if (rdGet >= 0 && rdGet < PASSWORD_CHAR.length) {  
				passwordSB.append(PASSWORD_CHAR[rdGet]);  
                count ++;  
            }  
		}
		seed +=1;
		return passwordSB.toString();
	}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章