> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# crypt.random

> 使用 random byte generator 生成 raw random bytes，并作为 Lua string 返回。

<div className="real-function-page">
  ```lua theme={null}
  crypt.random(size: number): string
  ```

  ## 参数

  <ParamField path={"size"} type={"number"} required>
    allocation 前传入 integer conversion 的数字。小于或等于 0 的值会触发 argument error。
  </ParamField>

  ## 返回值

  <ResponseField name={"bytes"} type={"string"}>
    以 Lua string 返回的 raw generated bytes。返回的 string 长度与分配的字节数一致。
  </ResponseField>

  ## 示例

  生成 raw bytes 并打印返回的 Lua string 长度。

  ```lua theme={null}
  local bytes = crypt.random(16)

  print(bytes)
  print(#bytes)
  ```
</div>
