feat(random): add explicitly granted OS entropy API

This commit is contained in:
Marqdo Agent committed 2026-11-21 10:25:11 +08:00
1 parent 6338fa10e9
commit ee0c6cc80a
20 files changed
+309 -15

No files matched your search

+2 -1
View File
@@ -17,6 +17,7 @@ module; a mismatch is a hard error.
- `data/table.mq.md` — value-returning table select/filter/sort/append/set/join/group/GFM
- `env.mq.md` — explicitly granted `env.get` names over `resource.request`
- `process.mq.md` — explicitly granted `process.run` with timeout/output caps
- `random.mq.md` — explicitly granted OS entropy bytes/integers
- `datetime.mq.md` — UTC ISO-8601 format/parse over Unix milliseconds (pure)
- `clock.mq.md` — project-mode `clock.now` over `resource.request`
- `path.mq.md` — lexical join/basename/dirname/extension/normalize (no I/O)
@@ -24,7 +25,7 @@ module; a mismatch is a hard error.
- `net/http.mq.md` — HTTP/1.1 response parsing (headers/chunked) and request builder
- `tests/` — product self-tests for every public module
(`clock`, `console`, `csv`, `datetime`, `demo`, `env`, `format`, `fs`, `http`,
`io`, `json`, `path`, `process`, `regex`, `stream`, `table`, `text`, `utf8`)
`io`, `json`, `path`, `process`, `random`, `regex`, `stream`, `table`, `text`, `utf8`)
The digest is a SHA-256 over sorted `*.mq.md` relative paths, a NUL, file
bytes, and a NUL. It excludes `stdlib.json` and non-`.mq.md` files. After any
+37
View File
@@ -0,0 +1,37 @@
## 字节
`(数量)`
读取 `数量` 个 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: 值 % 上限}*
+1 -1
View File
@@ -1,5 +1,5 @@
{
"name": "marqdo-stdlib",
"version": "0.1.0",
"digest": "sha256:6974496a9826f977189804bae0959e494bfc7443543ed4afffcea1ac390b0ce9"
"digest": "sha256:171c0d31cab5ae70ce6b16fc4c1cf819ab5a8e1895a801d5b2286b642dee5866"
}
+12
View File
@@ -0,0 +1,12 @@
---
import:
random: "std:random"
---
## main
**字节结果 = random.字节(16)**
**整数结果 = random.整数(100)**
*[字节结果.ok, 长度(字节结果.value), 整数结果.ok, 整数结果.value >= 0, 整数结果.value < 100]*