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.

Syntax
Luau
crypt.random(length: number) -> string

Parameters

Function parameters
ParameterTypeDescription
lengthnumberInteger number of raw bytes from 0 through 512.

Returns

string

A 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

Example
Luau
local bytes = crypt.random(16)
print("raw bytes:", #bytes)
print("text form:", base64encode(bytes))
Kawaii documentation