`
student_11
  • 浏览: 16247 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

JAVA 生存 随即6 位 字母+数字

 
阅读更多
/**
 * 0-9 ASC 48-57
 * A-Z ASC 65-90
 * a-z ASC 97-122
 */
package com.nutsbling.rand;

import java.util.Random;

public class RandNumCharacter {
	
	/**
	 * 
	 * @param begin 区间段的最小集合
	 * @param end 区间段的最大集合
	 * @return
	 */
	public static int iRandom(int []begin, int []end){
		Random r =new Random();
		int index = r.nextInt(begin.length); 
		int size = end[index]-begin[index];
		return r.nextInt(size)+begin[index]; //产生随机数后的ASC
		
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int []begin={48,65,97};
		int []end={57,90,122};
		char []c = new char[6];
		for(int i=0;i<6;i++){
			c[i]=(char) iRandom(begin, end);
		
		}
		System.out.println(new String(c));
	}

}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics