Class RandomData

java.lang.Object
cloud.opencode.base.test.data.RandomData

public final class RandomData extends Object
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 Details

    • uuid

      public static String uuid()
      Generates random UUID. 生成随机UUID。
      Returns:
      the UUID string | UUID字符串
    • shortUuid

      public static String shortUuid()
      Generates short UUID (first 8 characters). 生成短UUID(前8个字符)。
      Returns:
      the short UUID | 短UUID
    • compactUuid

      public static String 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

      public static String hex(int byteLength)
      Generates random bytes as hex string. 生成十六进制字符串形式的随机字节。
      Parameters:
      byteLength - number of bytes (output will be 2x length) | 字节数(输出长度为2倍)
      Returns:
      the hex string | 十六进制字符串
    • base64

      public static String base64(int byteLength)
      Generates random bytes as base64 string. 生成Base64字符串形式的随机字节。
      Parameters:
      byteLength - number of bytes | 字节数
      Returns:
      the base64 string | Base64字符串
    • base64Url

      public static String base64Url(int byteLength)
      Generates random bytes as URL-safe base64 string. 生成URL安全的Base64字符串形式的随机字节。
      Parameters:
      byteLength - number of bytes | 字节数
      Returns:
      the URL-safe base64 string | URL安全的Base64字符串
    • md5

      public static String md5()
      Generates random MD5 hash. 生成随机MD5哈希。
      Returns:
      the MD5 hash | MD5哈希
    • sha256

      public static String sha256()
      Generates random SHA-256 hash. 生成随机SHA-256哈希。
      Returns:
      the SHA-256 hash | SHA-256哈希
    • sha512

      public static String sha512()
      Generates random SHA-512 hash. 生成随机SHA-512哈希。
      Returns:
      the SHA-512 hash | SHA-512哈希
    • apiKey

      public static String apiKey()
      Generates random API key. 生成随机API密钥。
      Returns:
      the API key | API密钥
    • secretKey

      public static String secretKey()
      Generates random secret key. 生成随机密钥。
      Returns:
      the secret key | 密钥
    • accessToken

      public static String accessToken()
      Generates random access token. 生成随机访问令牌。
      Returns:
      the access token | 访问令牌
    • refreshToken

      public static String refreshToken()
      Generates random refresh token. 生成随机刷新令牌。
      Returns:
      the refresh token | 刷新令牌
    • numericCode

      public static String numericCode(int length)
      Generates random numeric code. 生成随机数字验证码。
      Parameters:
      length - the length | 长度
      Returns:
      the code | 验证码
    • alphanumericCode

      public static String alphanumericCode(int length)
      Generates random alphanumeric code. 生成随机字母数字验证码。
      Parameters:
      length - the length | 长度
      Returns:
      the code | 验证码
    • sequenceId

      public static String sequenceId(String prefix)
      Generates random sequence ID. 生成随机序列ID。
      Parameters:
      prefix - the prefix | 前缀
      Returns:
      the sequence ID | 序列ID
    • orderNumber

      public static String orderNumber()
      Generates random order number. 生成随机订单号。
      Returns:
      the order number | 订单号
    • transactionId

      public static String transactionId()
      Generates random transaction ID. 生成随机交易ID。
      Returns:
      the transaction ID | 交易ID