Files
marqdo-cli/stdlib/random.mq.md
T

38 lines
715 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 字节
`(数量)`
读取 `数量` 个 OS 熵字节,返回 `List<Int>`(每个 0–255)。仅项目模式,
需要显式 `--allow-random`;`pure`/`strict` 拒绝。
*resource.request("random.bytes", [数量])*
## 整数
`(上限)`
返回 `0 <= 值 < 上限` 的整数。`上限` 必须大于 0;使用 8 个熵字节
组合后取模(无偏拒绝采样尚未实现)。
1. `上限 <= 0`
*{ok: false, code: "random.invalid", message: "上限必须大于 0"}*
**字节结果 = 字节(8)**
1. `not 字节结果.ok`
*字节结果*
**值 = 0**
**下标 = 0**
- `下标 < 8`
**值 = 值 * 256 + 字节结果.value[下标]**
**下标 = 下标 + 1**
*{ok: true, value: 值 % 上限}*