Cryptography

crypt.random

Generates random bytes for nonces, salts, or temporary tokens.

Syntax

crypt.random(length: integer): string

Arguments

NameTypeDescription
lengthintegerNumber of bytes to generate.

Returns

NameTypeDescription
bytesstringRandom byte string with the requested length.

Description

Generates random bytes for nonces, salts, or temporary tokens.

Call it with 1 parameter(s): length. The argument table explains which values are required and which ones only refine the behavior.

It returns bytes (string). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Example call with placeholder values.

local result = crypt.random(1)
print(result)