Package com.gitee.apanlh.util.random
Class RandomCodeUtils
- java.lang.Object
-
- com.gitee.apanlh.util.random.RandomCodeUtils
-
public class RandomCodeUtils extends Object
随机生成工具提供纯数字和字母数字混合的随机字符串生成,线程安全
- Author:
- Pan
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MIXED_LENGTH默认混合长度static intDEFAULT_NUMERIC_LENGTH默认纯数字长度
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringrandom(int length, char[] charset)使用自定义字符集生成随机字符串static Stringrandom(int length, String string)使用自定义字符集生成随机字符串static StringrandomAlphanumeric()生成默认长度6位的字母数字混合字符串static StringrandomAlphanumeric(int length)生成指定长度的字母数字混合字符串static StringrandomNumeric()生成默认长度6位纯数字static StringrandomNumeric(int length)生成指定长度的纯数字
-
-
-
Field Detail
-
DEFAULT_NUMERIC_LENGTH
public static final int DEFAULT_NUMERIC_LENGTH
默认纯数字长度- See Also:
- Constant Field Values
-
DEFAULT_MIXED_LENGTH
public static final int DEFAULT_MIXED_LENGTH
默认混合长度- See Also:
- Constant Field Values
-
-
Method Detail
-
randomNumeric
public static String randomNumeric()
生成默认长度6位纯数字- Returns:
- String 6位数字字符串
-
randomNumeric
public static String randomNumeric(int length)
生成指定长度的纯数字- Parameters:
length- 长度,必须大于0- Returns:
- String 指定长度的数字字符串
- Throws:
IllegalArgumentException- 如果length <= 0
-
randomAlphanumeric
public static String randomAlphanumeric()
生成默认长度6位的字母数字混合字符串- Returns:
- String 6位字母数字混合字符串
-
randomAlphanumeric
public static String randomAlphanumeric(int length)
生成指定长度的字母数字混合字符串- Parameters:
length- 长度,必须大于0- Returns:
- String 指定长度的字母数字混合字符串
- Throws:
IllegalArgumentException- 如果length <= 0
-
random
public static String random(int length, String string)
使用自定义字符集生成随机字符串- Parameters:
length- 长度,必须大于0string- 字符串- Returns:
- String 随机字符串
- Throws:
IllegalArgumentException- 如果length <= 0 或 charset 为空
-
random
public static String random(int length, char[] charset)
使用自定义字符集生成随机字符串- Parameters:
length- 长度,必须大于0charset- 字符集数组,不能为空- Returns:
- String 随机字符串
- Throws:
IllegalArgumentException- 如果length <= 0 或 charset 为空
-
-