Class RandomData
java.lang.Object
cloud.opencode.base.test.data.RandomData
Random Data - Utilities for generating random data
随机数据 - 生成随机数据的工具
Provides thread-safe random data generation utilities.
提供线程安全的随机数据生成工具。
Features | 主要功能:
- UUID generation (full, short, compact) - UUID生成(完整、短、紧凑)
- Random bytes in hex, base64, URL-safe base64 formats - 十六进制、base64、URL安全base64格式随机字节
- Hash generation (MD5, SHA-256, SHA-512) - 哈希生成
- Token and code generation (API keys, access tokens, verification codes) - 令牌和验证码生成
Usage Examples | 使用示例:
String uuid = RandomData.uuid();
String hex = RandomData.hex(16);
String base64 = RandomData.base64(24);
byte[] bytes = RandomData.bytes(32);
Security | 安全性:
- Thread-safe: Yes (uses ThreadLocalRandom) - 线程安全: 是(使用ThreadLocalRandom)
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-test V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringGenerates random access token.static StringalphanumericCode(int length) Generates random alphanumeric code.static StringapiKey()Generates random API key.static Stringbase64(int byteLength) Generates random bytes as base64 string.static Stringbase64Url(int byteLength) Generates random bytes as URL-safe base64 string.static byte[]bytes(int length) Generates random bytes.static StringGenerates compact UUID (no dashes).static Stringhex(int byteLength) Generates random bytes as hex string.static Stringmd5()Generates random MD5 hash.static StringnumericCode(int length) Generates random numeric code.static StringGenerates random order number.static StringGenerates random refresh token.static StringGenerates random secret key.static StringsequenceId(String prefix) Generates random sequence ID.static Stringsha256()Generates random SHA-256 hash.static Stringsha512()Generates random SHA-512 hash.static StringGenerates short UUID (first 8 characters).static StringGenerates random transaction ID.static Stringuuid()Generates random UUID.
-
Method Details
-
uuid
-
shortUuid
Generates short UUID (first 8 characters). 生成短UUID(前8个字符)。- Returns:
- the short UUID | 短UUID
-
compactUuid
Generates compact UUID (no dashes). 生成紧凑UUID(无连字符)。- Returns:
- the compact UUID | 紧凑UUID
-
bytes
public static byte[] bytes(int length) Generates random bytes. 生成随机字节。- Parameters:
length- the length | 长度- Returns:
- the bytes | 字节数组
-
hex
Generates random bytes as hex string. 生成十六进制字符串形式的随机字节。- Parameters:
byteLength- number of bytes (output will be 2x length) | 字节数(输出长度为2倍)- Returns:
- the hex string | 十六进制字符串
-
base64
Generates random bytes as base64 string. 生成Base64字符串形式的随机字节。- Parameters:
byteLength- number of bytes | 字节数- Returns:
- the base64 string | Base64字符串
-
base64Url
Generates random bytes as URL-safe base64 string. 生成URL安全的Base64字符串形式的随机字节。- Parameters:
byteLength- number of bytes | 字节数- Returns:
- the URL-safe base64 string | URL安全的Base64字符串
-
md5
-
sha256
Generates random SHA-256 hash. 生成随机SHA-256哈希。- Returns:
- the SHA-256 hash | SHA-256哈希
-
sha512
Generates random SHA-512 hash. 生成随机SHA-512哈希。- Returns:
- the SHA-512 hash | SHA-512哈希
-
apiKey
-
secretKey
-
accessToken
Generates random access token. 生成随机访问令牌。- Returns:
- the access token | 访问令牌
-
refreshToken
Generates random refresh token. 生成随机刷新令牌。- Returns:
- the refresh token | 刷新令牌
-
numericCode
Generates random numeric code. 生成随机数字验证码。- Parameters:
length- the length | 长度- Returns:
- the code | 验证码
-
alphanumericCode
Generates random alphanumeric code. 生成随机字母数字验证码。- Parameters:
length- the length | 长度- Returns:
- the code | 验证码
-
sequenceId
-
orderNumber
Generates random order number. 生成随机订单号。- Returns:
- the order number | 订单号
-
transactionId
Generates random transaction ID. 生成随机交易ID。- Returns:
- the transaction ID | 交易ID
-