JDK工具类_____Random工具

import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Administrator
 * 验证码和密码初始化工具
 */
public class ValidateCode {
	
	public static void main(String[] args) {
		//验证码(登录验证码.短信验证码)
		directRandomCode();
		//随机数
		getRandomInt();
	}
	public static void directRandomCode() {
		//定义矩阵char数组	
		char[]chars={'1','2','3','4','5','6','7','8','9'};
		//随机码	
		StringBuffer sbf=new StringBuffer();
		for (int i = 0; i < 8; i++) {
			Random random=new Random();
			int a=random.nextInt(9);
			String code=String.valueOf(chars[a]);
			sbf.append(code);
		}
		System.out.println("验证码______:"+sbf.toString());
	}
	
	public static void getRandomInt(){
		Random random=new Random();
		System.out.println(random.nextInt(9));
	}
}

//运行结果


//


posted @ 2017-02-14 13:57  蜜獾互联网  阅读(9)  评论(0)    收藏  举报  来源