示例
rand_pcg 0.10.2: rand_pcg::rand_core::SeedableRng
已验证示例 — cargo rand_pcg 0.10.2: rand_pcg::rand_core::SeedableRng. contract 在 rust 1 · linux alpine/x64 · docker 上运行并通过: SeedableRng::seed_from_u64…
sha256:e3785ce032dfceebf1e63741cef28c1c248edb0bcf932879c2de1e06080477a7
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux · alpine · musl x64 cargo
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b… |
2026-11-29 |
案例
HOW- 目标
- verify rand_pcg::rand_core::SeedableRng in pkg:cargo/rand_pcg@0.10.2
- 符号
-
- rand_pcg::rand_core::SeedableRng
- 创建时间
- 2026-11-29T00:18:09Z
契约
- SeedableRng::seed_from_u64 deterministically seeds Pcg32, Pcg64, Pcg64Mcg, and Pcg64Dxsm and matches the Pcg64Mcg reference vector
- SeedableRng::from_seed constructs generators from fixed-size byte-array seeds ([u8; 16] and [u8; 32]) including all-zero seeds without panicking
- SeedableRng::from_rng and SeedableRng::try_from_rng seed child generators deterministically and propagate TryRng errors
- SeedableRng::fork and SeedableRng::try_fork produce deterministic child generators whose streams diverge from the parent
文件
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
源代码
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "rand_core"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
[[package]]
name = "rand_pcg"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a"
dependencies = [
"rand_core",
]
[[package]]
name = "sample-rand-pcg-seedable-rng"
version = "1.0.0"
dependencies = [
"rand_pcg",
]
[package]
name = "sample-rand-pcg-seedable-rng"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
rand_pcg = "=0.10.2"
[[bin]]
name = "contract"
path = "test/contract.rs"
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify rand_pcg::rand_core::SeedableRng in pkg:cargo/rand_pcg@0.10.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/rand_pcg@0.10.2
Demonstrate these symbols/APIs:
- rand_pcg::rand_core::SeedableRng
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:c1b6a779b6d7dc825f0e793b6fa6c1efa2aade5d39dc577362e05c26dd764fc6","contract":["SeedableRng::seed_from_u64 deterministically seeds Pcg32, Pcg64, Pcg64Mcg, and Pcg64Dxsm and matches the Pcg64Mcg reference vector","SeedableRng::from_seed constructs generators from fixed-size byte-array seeds ([u8; 16] and [u8; 32]) including all-zero seeds without panicking","SeedableRng::from_rng and SeedableRng::try_from_rng seed child generators deterministically and propagate TryRng errors","SeedableRng::fork and SeedableRng::try_fork produce deterministic child generators whose streams diverge from the parent"],"goal":"verify rand_pcg::rand_core::SeedableRng in pkg:cargo/rand_pcg@0.10.2","kind":"HOW","packages":["pkg:cargo/rand_pcg@0.10.2"],"schemaVersion":1,"symbols":["rand_pcg::rand_core::SeedableRng"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","distro":"alpine","ecosystem":"cargo","libc":"musl","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/rand_pcg@0.10.2"],"schemaVersion":1,"subject":"pkg:cargo/rand_pcg@0.10.2","symbols":["rand_pcg::rand_core::SeedableRng"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify rand_pcg::rand_core::SeedableRng in pkg:cargo/rand_pcg@0.10.2",
"kind": "HOW",
"packages": [
"pkg:cargo/rand_pcg@0.10.2"
],
"symbols": [
"rand_pcg::rand_core::SeedableRng"
]
}
//! Clean-room verification sample for rand_pcg::rand_core::SeedableRng.
pub use rand_pcg::rand_core::SeedableRng;
use core::fmt;
use rand_pcg::rand_core::{Rng, SeedableRng, TryRng};
use rand_pcg::{Pcg32, Pcg64, Pcg64Dxsm, Pcg64Mcg};
#[derive(Debug, PartialEq, Eq)]
struct FailingRngError;
impl fmt::Display for FailingRngError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("simulated rng source failure")
}
}
impl std::error::Error for FailingRngError {}
struct FailingRng;
impl TryRng for FailingRng {
type Error = FailingRngError;
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
Err(FailingRngError)
}
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
Err(FailingRngError)
}
fn try_fill_bytes(&mut self, _dst: &mut [u8]) -> Result<(), Self::Error> {
Err(FailingRngError)
}
}
fn main() {
// 1. SeedableRng::seed_from_u64 deterministically seeds Pcg32, Pcg64, Pcg64Mcg, and Pcg64Dxsm
let mut pcg32_a = Pcg32::seed_from_u64(42);
let mut pcg32_b = Pcg32::seed_from_u64(42);
let mut pcg32_other = Pcg32::seed_from_u64(43);
let seq_a = [pcg32_a.next_u32(), pcg32_a.next_u32(), pcg32_a.next_u32()];
let seq_b = [pcg32_b.next_u32(), pcg32_b.next_u32(), pcg32_b.next_u32()];
let seq_other = [
pcg32_other.next_u32(),
pcg32_other.next_u32(),
pcg32_other.next_u32(),
];
assert_eq!(seq_a, seq_b);
assert_ne!(seq_a, seq_other);
let mut pcg64_a = Pcg64::seed_from_u64(12345);
let mut pcg64_b = Pcg64::seed_from_u64(12345);
assert_eq!(pcg64_a.next_u64(), pcg64_b.next_u64());
let mut pcg64_dxsm_a = Pcg64Dxsm::seed_from_u64(99);
let mut pcg64_dxsm_b = Pcg64Dxsm::seed_from_u64(99);
assert_eq!(pcg64_dxsm_a.next_u64(), pcg64_dxsm_b.next_u64());
let mut pcg64_mcg_zero = Pcg64Mcg::seed_from_u64(0);
assert_eq!(pcg64_mcg_zero.next_u64(), 0x5603_f242_407d_eca2);
// 2. SeedableRng::from_seed accepts fixed-size byte array seeds including all-zero seeds
let seed16: <Pcg32 as SeedableRng>::Seed = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
];
let mut from_seed32_a = Pcg32::from_seed(seed16);
let mut from_seed32_b = Pcg32::from_seed(seed16);
assert_eq!(from_seed32_a.next_u32(), from_seed32_b.next_u32());
assert_eq!(from_seed32_a.next_u64(), from_seed32_b.next_u64());
let zero_seed16 = [0u8; 16];
let mut zero_pcg32 = Pcg32::from_seed(zero_seed16);
let mut zero_pcg64_mcg = Pcg64Mcg::from_seed(zero_seed16);
let _ = zero_pcg32.next_u32();
let _ = zero_pcg64_mcg.next_u64();
let seed32: <Pcg64 as SeedableRng>::Seed = [0x5Au8; 32];
let mut from_seed64_a = Pcg64::from_seed(seed32);
let mut from_seed64_b = Pcg64::from_seed(seed32);
assert_eq!(from_seed64_a.next_u64(), from_seed64_b.next_u64());
let zero_seed32: <Pcg64Dxsm as SeedableRng>::Seed = [0u8; 32];
let mut zero_dxsm_a = Pcg64Dxsm::from_seed(zero_seed32);
let mut zero_dxsm_b = Pcg64Dxsm::from_seed(zero_seed32);
assert_eq!(zero_dxsm_a.next_u64(), zero_dxsm_b.next_u64());
// 3. SeedableRng::from_rng and try_from_rng seed deterministically and propagate errors
let mut master_a = Pcg64::seed_from_u64(777);
let mut master_b = Pcg64::seed_from_u64(777);
let mut child_from_rng = Pcg32::from_rng(&mut master_a);
let mut child_try_from_rng =
Pcg32::try_from_rng(&mut master_b).expect("infallible rng should succeed");
assert_eq!(child_from_rng.next_u64(), child_try_from_rng.next_u64());
let mut failing = FailingRng;
let err = Pcg32::try_from_rng(&mut failing).expect_err("failing rng must propagate error");
assert_eq!(err, FailingRngError);
// 4. SeedableRng::fork and try_fork produce deterministic independent child streams
let mut parent_a = Pcg64Dxsm::seed_from_u64(2026);
let mut parent_b = Pcg64Dxsm::seed_from_u64(2026);
let mut forked_a = parent_a.fork();
let mut forked_b = parent_b.try_fork().expect("infallible try_fork should succeed");
let child_vals_a = [forked_a.next_u64(), forked_a.next_u64()];
let child_vals_b = [forked_b.next_u64(), forked_b.next_u64()];
assert_eq!(child_vals_a, child_vals_b);
let parent_vals_a = [parent_a.next_u64(), parent_a.next_u64()];
let parent_vals_b = [parent_b.next_u64(), parent_b.next_u64()];
assert_eq!(parent_vals_a, parent_vals_b);
assert_ne!(child_vals_a, parent_vals_a);
println!("All rand_pcg::rand_core::SeedableRng contract assertions passed.");
}
原始种子者
匿名