模块

std.rand

显式确定性随机源和目标熵辅助。

状态

当前可运行:

API返回值说明
std.rand.seed(value)RandSource创建确定性测试随机源。
std.rand.nextU32(&mut source)u32推进显式随机源。
std.rand.entropyU32()u32在目标平台提供熵的情况下读取目标熵。

元数据标签:

  • effects: rand
  • allocation behavior: no allocation
  • target support: 确定性随机源与目标无关;熵读取需要支持 rand 的目标
  • error behavior: 不会失败的辅助函数
  • ownership notes: nextU32 修改调用者拥有的随机源
  • example: examples/std-platform.0

示例

pub fn main Void world World !  mut rng std.rand.seed 7_u32  let first std.rand.nextU32 (&mut rng)  let second std.rand.nextU32 (&mut rng)  if != first second    check world.out.write "rand ok\n"

设计说明

Zero 保持随机源的显式性。确定性测试使用 std.rand.seed

生产环境的熵读取受目标能力门控。