Syntax
crypt.random(size: number): stringArguments
| Name | Type | Description |
|---|---|---|
size | number | Number converted to an integer before allocation. Values less than or equal to 0 raise an argument error. |
Returns
| Name | Type | Description |
|---|---|---|
bytes | string | Raw generated bytes returned as a Lua string. The returned string length matches the allocated byte count. |
Description
Generates raw random bytes with random byte generator and returns them as a Lua string.
Call it with 1 parameter(s): size. 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
Generate raw bytes and print the returned Lua string length.
local bytes = crypt.random(16)
print(bytes)
print(#bytes)