Java随即生成指定长度字符串

	/**
	 * 生成制定长度验证码
	 * @param verifyCode_len 验证码长度
	 * @return
	 * String
	 */
	private String getRandmonVerifyCode(int verifyCode_len){
		char[] c = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
		int maxNum = 10;
		int count = 0;//记录验证码长度
		
		StringBuffer verifyCodeStr = new StringBuffer();
		Random random = new Random();
		while(count < verifyCode_len){
			int i = random.nextInt(maxNum);
			if(i >= 0 && i < c.length){
				verifyCodeStr.append(String.valueOf(i));
				count++;
			}
		}
		return verifyCodeStr.toString();
	}
 

 

你可能感兴趣的:(java,C++,c,C#)