手机验证码工具类RandomUtils

/**
 * 随机生成位数工具类
 * @author caidongqu
 */
public class RandomUtils {

	public static void main(String[] args) throws InterruptedException {
		Random random = new Random();
		System.out.println(random.nextInt(4));
		for (int i = 0; i < 100; i++) {
			new Thread(new Runnable() {
				@Override
				public void run() {
					System.out.println(getRandomNum());
					System.out.println(getRandomNum3());
					System.out.println(getRandomNum4());
					System.out.println(getRandomNum6());

				}
			}).start();
		}
		Thread.currentThread().sleep(40000);
		
	}

	private static Random random = new Random();
	/**
	 * 随机数50-150
	 */
	public static int getRandomNum(){
		int x = random.nextInt(100);
		return x+50;
	}
	
	/**
	 * 手机注册六位校验码生成
	 */
	public static String getRandomNum6(){
		int x = random.nextInt(899999);
		return x+100000+"";
	}
	
	/**
	 * 手机注册四位校验码生成
	 */
	public static String getRandomNum4(){
		int x = random.nextInt(8999);
		return x+1000+"";
	}
	
	/**
	 * 生产3位数的随机数
	 */
	public static String getRandomNum3(){
		int x = random.nextInt(899);
		return x+100+"";
	}

	/**
	 * 月日时分秒+随机8位数
	 */
	public static String getTimeRandomNum(){
		int x = random.nextInt(89999999);
		 x=x+10000000;
		 return DateUtils.dateToString(new Date(),"MMddHHmmss")+x;
	}
	
}


猜你喜欢

转载自blog.csdn.net/LC_Liangchao/article/details/121848675