crypt.generatebytes Synchronous

Generate random bytes and return them encoded as Base64. Use it when a random value must already be printable, such as a randomly generated local label. Requesting 16 bytes does not mean the Base64 result has 16 characters.

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

Parameters

Function parameters
ParameterTypeDescription
lengthnumberNumber of random bytes before encoding. Must be an integer from 0 through 512.

Returns

string

Base64 text. The string length after encoding differs from the requested byte count.

Example

Example
Luau
local encoded = crypt.generatebytes(16)
local bytes = base64decode(encoded)
print(#bytes) -- 16
Kawaii documentation