RandomUtil.java 914 Bytes
package com.yoho.unions.utils;

import java.util.Random;

public class RandomUtil {

	public static String autoGetPassword() {
		StringBuilder sb = new StringBuilder();
		Random random = new Random();
		sb.append(random.nextInt(1000000));
		sb.append("yh");
		return sb.toString();
	}
	
	/**
     * java生成随机数字和字母组合
     * @param length[生成随机数的长度]
     * @return
     */
	public static String getCharAndNumr(int numLength,int charLength) {
        String val = "";
        Random random = new Random();
        for (int i = 0; i < numLength; i++) {
            // 输出字母还是数字
            val += String.valueOf(random.nextInt(10));	            
        }
        for(int j=0;j<charLength;j++){
        	 int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; 
             val += (char) (choice + random.nextInt(26));
        }
        return val.toLowerCase();
    }
}