Files
marqdo-std-system/modules/random.mq.md
cflmy 053ddb0e59 migrate: own clock/datetime/env/process/random sources and baseline assertions
Move the official stdlib system modules to their unique source authority without
changing public std: paths or host authorization. Carry the pre-migration product
assertions into component cases captured from the baseline Bundle; the process
case resolves the granted program and expected stdout from the verified CLI.

Refs cflmy/marqdo#9, cflmy/marqdo-std-system#1
2026-11-26 23:30:25 +08:00

769 B
Raw Permalink Blame History

@exec random

字节

params(数量)

读取 数量 个 OS 熵字节,返回 List(每个 0–255)。仅项目模式, 需要显式 --allow-random;pure/strict 拒绝。

return resource.request("random.bytes", [数量])

整数

params(上限)

返回 0 <= 值 < 上限 的整数。上限 必须大于 0;使用 8 个熵字节 组合后取模(无偏拒绝采样尚未实现)。

if 上限 <= 0

return {ok: false, code: "random.invalid", message: "上限必须大于 0"}

end 字节结果 = 字节(8)

if not 字节结果.ok

return 字节结果

end 值 = 0

下标 = 0

while 下标 < 8

值 = 值 * 256 + 字节结果.value[下标]

下标 = 下标 + 1

end return {ok: true, value: 值 % 上限}