Class OpenRandom
java.lang.Object
cloud.opencode.base.core.random.OpenRandom
Random Utility Class - Comprehensive random generation utilities
随机工具类 - 全面的随机生成工具
Provides random number, string, UUID generation with ThreadLocalRandom and SecureRandom.
提供基于 ThreadLocalRandom 和 SecureRandom 的随机数、字符串、UUID 生成。
Features | 主要功能:
- Random numbers (int, long, double, boolean) - 随机数生成
- Random strings (alphanumeric, numeric, alphabetic) - 随机字符串
- Secure random (cryptographically strong) - 安全随机数
- UUID generation (standard and simple) - UUID 生成
- Collection random (element selection, shuffle) - 集合随机操作
Usage Examples | 使用示例:
int num = OpenRandom.randomInt(100);
String code = OpenRandom.randomAlphanumeric(8);
String uuid = OpenRandom.simpleUUID();
String element = OpenRandom.randomElement(list);
OpenRandom.shuffle(array);
Security | 安全性:
- Thread-safe: Yes (ThreadLocalRandom) - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringrandomAlphabetic(int length) Generates a random alphabetic string 生成随机字母字符串static StringrandomAlphanumeric(int length) Generates a random alphanumeric string 生成随机字母数字字符串static booleanGenerates a random boolean 生成随机布尔值static byte[]randomBytes(int length) Generates a random byte array 生成随机字节数组static LocalDaterandomDate(int startYear, int endYear) Generates a random date [startYear, endYear) 生成随机日期 [startYear, endYear)static LocalDaterandomDate(LocalDate start, LocalDate end) Generates a random date (specified range) 生成随机日期(指定范围)static doubleGenerates a random double [0, 1) 生成随机浮点数 [0, 1)static doublerandomDouble(double bound) Generates a random double [0, bound) 生成随机浮点数 [0, bound)static doublerandomDouble(double origin, double bound) Generates a random double [origin, bound) 生成随机浮点数 [origin, bound)static <T> TrandomElement(List<T> list) Selects a random element from a list 从列表随机选择元素static <T> TrandomElement(T... array) Selects a random element from an array 从数组随机选择元素static <T> List<T> randomElements(List<T> list, int count) Selects multiple random elements from a collection 从集合随机选择多个元素static intrandomInt(int bound) Generates a random integer [0, bound) 生成随机整数 [0, bound)static intrandomInt(int origin, int bound) Generates a random integer [origin, bound) 生成随机整数 [origin, bound)static longrandomLong(long bound) Generates a random long [0, bound) 生成随机长整数 [0, bound)static longrandomLong(long origin, long bound) Generates a random long [origin, bound) 生成随机长整数 [origin, bound)static StringrandomLowerCase(int length) Generates a random lowercase string 生成随机小写字母字符串static StringrandomNumeric(int length) Generates a random numeric string 生成随机数字字符串static StringrandomString(int length, String chars) Generates a random string (custom character set) 生成随机字符串(自定义字符集)static StringrandomUpperCase(int length) Generates a random uppercase string 生成随机大写字母字符串static StringsecureAlphanumeric(int length) Generates a secure random alphanumeric string 生成安全随机字母数字字符串static byte[]secureBytes(int length) Generates a secure random byte array 生成安全随机字节数组static intsecureInt(int bound) Generates a secure random integer 生成安全随机整数static longGenerates a secure random long 生成安全随机长整数static StringsecureString(int length, String chars) Generates a secure random string (custom character set) 生成安全随机字符串(自定义字符集)static StringGenerates a secure UUID (based on SecureRandom) 生成安全 UUID(基于 SecureRandom)static <T> voidShuffles a list 打乱列表顺序static <T> voidshuffle(T[] array) Shuffles an array 打乱数组顺序static StringGenerates a simple UUID (without hyphens) 生成简单 UUID(无横线)static Stringuuid()Generates a UUID 生成 UUID
-
Method Details
-
randomInt
public static int randomInt(int bound) Generates a random integer [0, bound) 生成随机整数 [0, bound) -
randomInt
public static int randomInt(int origin, int bound) Generates a random integer [origin, bound) 生成随机整数 [origin, bound) -
randomLong
public static long randomLong(long bound) Generates a random long [0, bound) 生成随机长整数 [0, bound) -
randomLong
public static long randomLong(long origin, long bound) Generates a random long [origin, bound) 生成随机长整数 [origin, bound) -
randomDouble
public static double randomDouble()Generates a random double [0, 1) 生成随机浮点数 [0, 1) -
randomDouble
public static double randomDouble(double bound) Generates a random double [0, bound) 生成随机浮点数 [0, bound) -
randomDouble
public static double randomDouble(double origin, double bound) Generates a random double [origin, bound) 生成随机浮点数 [origin, bound) -
randomBoolean
public static boolean randomBoolean()Generates a random boolean 生成随机布尔值 -
randomBytes
public static byte[] randomBytes(int length) Generates a random byte array 生成随机字节数组 -
secureBytes
public static byte[] secureBytes(int length) Generates a secure random byte array 生成安全随机字节数组 -
secureInt
public static int secureInt(int bound) Generates a secure random integer 生成安全随机整数 -
secureLong
public static long secureLong()Generates a secure random long 生成安全随机长整数 -
randomAlphanumeric
Generates a random alphanumeric string 生成随机字母数字字符串 -
secureAlphanumeric
Generates a secure random alphanumeric string 生成安全随机字母数字字符串 -
randomNumeric
Generates a random numeric string 生成随机数字字符串 -
randomAlphabetic
Generates a random alphabetic string 生成随机字母字符串 -
randomUpperCase
Generates a random uppercase string 生成随机大写字母字符串 -
randomLowerCase
Generates a random lowercase string 生成随机小写字母字符串 -
randomString
-
secureString
-
uuid
Generates a UUID 生成 UUID -
simpleUUID
Generates a simple UUID (without hyphens) 生成简单 UUID(无横线) -
secureUUID
Generates a secure UUID (based on SecureRandom) 生成安全 UUID(基于 SecureRandom) -
randomElement
Selects a random element from a list 从列表随机选择元素 -
randomElement
Selects a random element from an array 从数组随机选择元素 -
randomElements
-
shuffle
Shuffles a list 打乱列表顺序 -
shuffle
public static <T> void shuffle(T[] array) Shuffles an array 打乱数组顺序 -
randomDate
Generates a random date [startYear, endYear) 生成随机日期 [startYear, endYear) -
randomDate
-