All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.nowtd.jtools.random.Random Maven / Gradle / Ivy

There is a newer version: 1.9.5
Show newest version
package com.gitee.nowtd.jtools.random;

public class Random {
	public static String randomStr(String mainChars, int length) {
		String[] chars = mainChars.split("");
		java.util.Random random = new java.util.Random();
		String text = "";
		int r, i = 0;
		
		for (; i < length; i ++) {
			r = random.nextInt(chars.length);
			text += chars[r];
		}
		
		return text;
	}
	
	public static String rString(int length) {
		return randomStr("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789", length);
	}
	
	public static String rString(String suffix, int length) {
		return suffix + rString(length);
	}
	
	public static String rInt(int length) {
		return randomStr("0123456789", length);
	}
	
	public static String rInt(int suffix, int length) {
		return String.valueOf(suffix) + rInt(length);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy