RandomStringUtils生成随机数相关方法

import org.apache.commons.lang3.RandomStringUtils;

public class RandomUtil {

	/**
	 * count 创建一个随机字符串,其长度是指定的字符数,字符将从参数的字母数字字符集中选择,如参数所示。 
	 * letterstrue,生成的字符串可以包括字母字符 
	 * numbers true,生成的字符串可以包含数字字符
	 */
	public static String random(int count, boolean letters, boolean numbers) {
		return RandomStringUtils.random(count, letters, numbers);
	}

	/**
	 * 创建一个随机字符串,其长度是指定的字符数。 
	 * 将从所有字符集中选择字符
	 */
	public static String random(int count) {
		return RandomStringUtils.random(count);
	}

	/**
	 * 创建一个随机字符串,其长度是指定的字符数。 
	 * 字符将从字符串指定的字符集中选择,不能为空。如果NULL,则使用所有字符集。
	 */
	public static String random(int count, String chars) {
		return RandomStringUtils.random(count, chars);
	}

	/**
	 * 创建一个随机字符串,其长度是指定的字符数,字符将从参数的字母数字字符集中选择,如参数所示。 
	 * count:计算创建的随机字符长度
	 * start:字符集在开始时的位置 
	 * end:字符集在结束前的位置,必须大于65 
	 * letters true,生成的字符串可以包括字母字符 
	 * numbers true,生成的字符串可以包含数字字符
	 * 
	 */
	public static String random(int count, int start, int end, boolean letters, boolean numbers) {
		return RandomStringUtils.random(count, start, end, letters, numbers);
	}

	/**
	 * 产生一个长度为指定的随机字符串的字符数,字符将从拉丁字母(a-z、A-Z的选择)。 
	 * count:创建随机字符串的长度
	 */
	public static String randomAlphabetic(int count) {
		return RandomStringUtils.randomAlphabetic(count);
	}

	/**
	 * 创建一个随机字符串,其长度介于包含最小值和最大最大值之间,,字符将从拉丁字母(a-z、A-Z的选择)。 
	 * minLengthInclusive :要生成的字符串的包含最小长度 
	 * maxLengthExclusive :要生成的字符串的包含最大长度
	 */
	public static String randomAlphabetic(int minLengthInclusive, int maxLengthExclusive) {
		return RandomStringUtils.randomAlphabetic(minLengthInclusive, maxLengthExclusive);
	}

	/**
	 * 创建一个随机字符串,其长度是指定的字符数,字符将从拉丁字母(a-z、A-Z)和数字0-9中选择。 
	 * count :创建的随机数长度
	 */
	public static String randomAlphanumeric(int count) {
		return RandomStringUtils.randomAlphanumeric(count);
	}

	/**
	 * 创建一个随机字符串,其长度介于包含最小值和最大最大值之间,字符将从拉丁字母(a-z、A-Z)和数字0-9中选择。 
	 * minLengthInclusive:要生成的字符串的包含最小长度 
	 * maxLengthExclusive :要生成的字符串的包含最大长度
	 * 
	 */
	public static String randomAlphanumeric(int minLengthInclusive, int maxLengthExclusive) {
		return RandomStringUtils.randomAlphanumeric(minLengthInclusive, maxLengthExclusive);
	}

	/**
	 * 创建一个随机字符串,其长度是指定的字符数,字符将从ASCII值介于32到126之间的字符集中选择(包括) 
	 * count:随机字符串的长度
	 */
	public static String randomAscii(int count) {
		return RandomStringUtils.randomAscii(count);
	}

	/**
	 * 创建一个随机字符串,其长度介于包含最小值和最大最大值之间,字符将从ASCII值介于32到126之间的字符集中选择(包括)
	 * minLengthInclusive :要生成的字符串的包含最小长度 
	 * maxLengthExclusive :要生成的字符串的包含最大长度
	 */
	public static String randomAscii(int minLengthInclusive, int maxLengthExclusive) {
		return RandomStringUtils.randomAscii(minLengthInclusive, maxLengthExclusive);
	}

	/**
	 * 创建一个随机字符串,其长度是指定的字符数,将从数字字符集中选择字符。 
	 * count:生成随机数的长度
	 */
	public static String randomNumeric(int count) {
		return RandomStringUtils.randomNumeric(count);
	}

	/**
	 * 创建一个随机字符串,其长度介于包含最小值和最大最大值之间,将从数字字符集中选择字符. 
	 * minLengthInclusive, 要生成的字符串的包含最小长度
	 * maxLengthExclusive 要生成的字符串的包含最大长度
	 */
	public static String randomNumeric(int minLengthInclusive, int maxLengthExclusive) {
		return RandomStringUtils.randomNumeric(minLengthInclusive, maxLengthExclusive);
	}
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值