Skip to content

std.rand

tier: std · since: std-0.2 stability: experimental

确定性伪随机(MINSTD/Park–Miller + Schrage;I64 承载 I32 值域) 口径:种子型纯函数,无全局状态、无真实熵(宪章 8);模数 2147483647(2^31−1); 真实熵源归系统域(process),本模块恒可复现; 实现纪律(C10):状态/算术全程 I64 宽域(I32 界邻值会触发解释器算术门)

pub fn

Signature Returns Description
rng_seed(s: I64) I64 种子规范化:v ≤ 0 加 M;≥ M 减 M−1;收敛进 [1, 2147483646]
rng_fresh() I64 默认种子(固定 1;确定性)
rng_next(s: I64) I64 单步:s' = 16807·s mod 2147483647(Schrage:16807·lo − 2836·hi)
rng_range(s: I64, lo: I32, hi: I32) I32 [lo, hi) 均匀整数;hi ≤ lo 返回 lo(文档化,非 panic)
rng_shuffle[T](xs: List[T], s: I64) List[T] Fisher–Yates 逆洗(从尾到头);返回新 List,原值不变(宪章 3)