Skip to content
Encoding & cryptographyReference

crypt.random

Generate a raw binary string of random bytes.

Details#

Generate a raw binary string of random bytes. Exactly size raw bytes; 0 returns an empty string. Invalid sizes and generator failure raise errors.

Signature#

Luau
crypt.random(size: number): string

Parameters#

ParameterTypeDescription
sizenumberInteger byte count from 0 to 1048576.

Returns#

Exactly size raw bytes; 0 returns an empty string. Invalid sizes and generator failure raise errors.

Examples#

Local example

Luau
local bytes = crypt.random(16)
print(#bytes) -- 16