package com.qs.mp.common.utils;

import java.util.Random;

public class RandomStr {
	private static Random randGen = null;
	private static char[] numbersAndLetters = null;

	public static final String randomNum(int length) {
		if (length < 1) {
			return null;
		}
		if (randGen == null) {
			randGen = new Random();
			numbersAndLetters = "01234567890236985471458745651355666581256984136598745632159556369812659741668"
					.toCharArray();
		}

		char[] randBuffer = new char[length];
		for (int i = 0; i < randBuffer.length; i++) {
			randBuffer[i] = numbersAndLetters[randGen.nextInt(71)];
		}

		return new String(randBuffer);
	}

	public static String randomAbc(int length) { // length表示生成字符串的长度
		String base = "QWERTYUIOPASDFGHJKLZXCVBNMQWERTYUIOPASDFGHJKLZXCVBNM";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}

	public static void main(String[] args) {
		System.out.println(randomAbc(6));
	}

}