API Reference › Crypto › Crypto.random_hex
method

Crypto.random_hex

Crypto.random_hex(n) -> string

Identical to Crypto.random_bytes: draws n bytes from the OS CSPRNG and returns them as a 2n-character lowercase hex string. The two names are interchangeable; random_hex exists so call sites can be explicit that the return value is already hex text (not raw bytes) when that reads more clearly. The same determinism caveat applies — the result is unpredictable by design and must stay out of the reproducible simulation RNG.

Parameters

nthe number of secure random bytes to draw

Example

program Nonce {
  entry {
    let nonce = Crypto.random_hex(12)   # 24 hex chars
    print(len(nonce))                    # 24
  }
}
← All symbols