Package com.acanx.utils.incubator
Class RandomUtil
java.lang.Object
com.acanx.utils.incubator.RandomUtil
RandomUtil
- Since:
- 0.0.1.10
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetRandomNum(int length) 生成随机数字符串static StringgetRandomStr(int length) 生成指定长度的随机字符串static Stringrandom(int count, int start, int end, boolean letters, boolean numbers, char[] chars, Random random) 来自 package org.apache.commons.lang3.RandomStringUtils;
-
Method Details
-
getRandomStr
生成指定长度的随机字符串- Parameters:
length- String 字符串长度- Returns:
- String 生成的字符串
-
random
public static String random(int count, int start, int end, boolean letters, boolean numbers, char[] chars, Random random) 来自 package org.apache.commons.lang3.RandomStringUtils;Creates a random string based on a variety of options, using supplied source of randomness.
If start and end are both
0, start and end are set to' 'and'z', the ASCII printable characters, will be used, unless letters and numbers are bothfalse, in which case, start and end are set to0andCharacter.MAX_CODE_POINT.If set is not
null, characters between start and end are chosen.This method accepts a user-supplied
Randominstance to use as a source of randomness. By seeding a singleRandominstance with a fixed seed and using it for each call, the same random sequence of strings can be generated repeatedly and predictably.- Parameters:
count- 生成的目标字符串长度start- the position in set of chars to start at (inclusive)end- the position in set of chars to end before (exclusive)letters- only allow letters?numbers- 只允许数字?chars- the set of chars to choose randoms from, must not be empty. Ifnull, then it will use the set of all chars.random- a source of randomness.- Returns:
- the random string
- Throws:
ArrayIndexOutOfBoundsException- if there are not(end - start) + 1characters in the set array.IllegalArgumentException- ifcount< 0 or the provided chars array is empty.- Since:
- 2.0
-
getRandomNum
生成随机数字符串- Parameters:
length- 长度- Returns:
- 随机数字符串
-