crypt. random Synchronous
Request random bytes directly when an API expects binary key material, a nonce, or another byte string. Encode them separately if they must be printed or placed in JSON.
Luau
crypt.random(length: number) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
length | number | Integer number of raw bytes from 0 through 512. |
Returns
stringA raw byte string that may contain zero bytes and other nonprintable characters.
Usage notes
For a ready-to-store Base64 value, crypt.generatebytes performs the encoding for you.
Example
Luau
local bytes = crypt.random(16)
print("raw bytes:", #bytes)
print("text form:", base64encode(bytes))