Beispiel
rand_core 0.9.5: rand_core::SeedableRng
Verifiziertes Beispiel für cargo rand_core 0.9.5: rand_core::SeedableRng. Der Vertrag lief auf rust 1 · linux alpine/x64 · docker und bestand.
sha256:7006fb5cd041f54ad30658f0861f55ed63f8dd134c654847b59277fa0728c14c
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
linux · alpine · musl x64 cargo
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| 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-10-13 |
Fall
HOW- Ziel
- verify rand_core::SeedableRng in pkg:cargo/rand_core@0.9.5
- Pakete
- Symbole
-
- rand_core::SeedableRng
- Erstellt
- 2026-10-13T05:17:05Z
Contract
- SeedableRng::from_seed initializes PRNG deterministically from raw seed bytes
- SeedableRng::seed_from_u64 constructs PRNG reproducible from u64 state
- SeedableRng::from_rng seeds a child PRNG from another RngCore instance
- SeedableRng::try_from_rng seeds a PRNG from a TryRngCore source and propagates errors
Dateien
- Cargo.lock
- Cargo.toml
- PROMPT.md
- csx.json
- spec.json
- src/lib.rs
- test/contract.rs
Quelltext
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "rand_core"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
[[package]]
name = "sample-rand-core"
version = "1.0.0"
dependencies = [
"rand_core",
]
[package]
name = "sample-rand-core"
version = "1.0.0"
edition = "2021"
publish = false
[dependencies]
rand_core = { version = "=0.9.5" }
[[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_core::SeedableRng in pkg:cargo/rand_core@0.9.5
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:cargo/rand_core@0.9.5
Demonstrate these symbols/APIs:
- 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:d623618cb99fdc4211cc1a7ede4d800df9f285cdf819761c83741e72a1897b8b","contract":["SeedableRng::from_seed initializes PRNG deterministically from raw seed bytes","SeedableRng::seed_from_u64 constructs PRNG reproducible from u64 state","SeedableRng::from_rng seeds a child PRNG from another RngCore instance","SeedableRng::try_from_rng seeds a PRNG from a TryRngCore source and propagates errors"],"goal":"verify rand_core::SeedableRng in pkg:cargo/rand_core@0.9.5","kind":"HOW","packages":["pkg:cargo/rand_core@0.9.5"],"schemaVersion":1,"symbols":["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_core@0.9.5"],"schemaVersion":1,"subject":"pkg:cargo/rand_core@0.9.5","symbols":["rand_core::SeedableRng"],"verifierAdapter":"cargo@1"}
{
"schemaVersion": 1,
"goal": "verify rand_core::SeedableRng in pkg:cargo/rand_core@0.9.5",
"kind": "HOW",
"packages": [
"pkg:cargo/rand_core@0.9.5"
],
"symbols": [
"rand_core::SeedableRng"
]
}
//! Clean-room verification sample for rand_core::SeedableRng.
pub use rand_core::SeedableRng;
use rand_core::{RngCore, SeedableRng, TryRngCore};
#[derive(Debug, Clone, PartialEq, Eq)]
struct StepRng {
state: u64,
step: u64,
}
impl StepRng {
fn new(state: u64, step: u64) -> Self {
Self { state, step }
}
}
impl RngCore for StepRng {
fn next_u32(&mut self) -> u32 {
self.next_u64() as u32
}
fn next_u64(&mut self) -> u64 {
let val = self.state;
self.state = self.state.wrapping_add(self.step);
val
}
fn fill_bytes(&mut self, dest: &mut [u8]) {
let mut chunks = dest.chunks_exact_mut(8);
for chunk in &mut chunks {
chunk.copy_from_slice(&self.next_u64().to_le_bytes());
}
let rem = chunks.into_remainder();
if !rem.is_empty() {
let bytes = self.next_u64().to_le_bytes();
rem.copy_from_slice(&bytes[..rem.len()]);
}
}
}
impl SeedableRng for StepRng {
type Seed = [u8; 16];
fn from_seed(seed: Self::Seed) -> Self {
let state = u64::from_le_bytes(seed[0..8].try_into().unwrap());
let step = u64::from_le_bytes(seed[8..16].try_into().unwrap());
Self::new(state, step)
}
}
#[derive(Debug, PartialEq, Eq)]
struct DummyError;
impl core::fmt::Display for DummyError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "DummyError")
}
}
struct FailingRng;
impl TryRngCore for FailingRng {
type Error = DummyError;
fn try_next_u32(&mut self) -> Result<u32, Self::Error> {
Err(DummyError)
}
fn try_next_u64(&mut self) -> Result<u64, Self::Error> {
Err(DummyError)
}
fn try_fill_bytes(&mut self, _dst: &mut [u8]) -> Result<(), Self::Error> {
Err(DummyError)
}
}
fn main() {
// 1. SeedableRng::from_seed initializes PRNG deterministically from raw seed bytes
let seed1: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
let mut rng1 = StepRng::from_seed(seed1);
let mut rng2 = StepRng::from_seed(seed1);
assert_eq!(rng1.next_u64(), rng2.next_u64());
assert_eq!(rng1.next_u64(), rng2.next_u64());
// 2. SeedableRng::seed_from_u64 constructs PRNG reproducible from u64 state
let mut rng_u64_a = StepRng::seed_from_u64(0x1234_5678_9abc_def0);
let mut rng_u64_b = StepRng::seed_from_u64(0x1234_5678_9abc_def0);
assert_eq!(rng_u64_a.next_u64(), rng_u64_b.next_u64());
assert_eq!(rng_u64_a.next_u64(), rng_u64_b.next_u64());
let mut rng_u64_c = StepRng::seed_from_u64(0xdead_beef);
assert_ne!(rng_u64_a.next_u64(), rng_u64_c.next_u64());
// 3. SeedableRng::from_rng seeds a child PRNG from another RngCore instance
let mut master = StepRng::seed_from_u64(42);
let mut child1 = StepRng::from_rng(&mut master);
let mut child2 = StepRng::from_rng(&mut master);
assert_ne!(child1.next_u64(), child2.next_u64());
// 4. SeedableRng::try_from_rng seeds a PRNG from a TryRngCore source and propagates errors
let mut source = StepRng::seed_from_u64(100);
let child_ok = StepRng::try_from_rng(&mut source);
assert!(child_ok.is_ok());
let mut failing = FailingRng;
let child_err = StepRng::try_from_rng(&mut failing);
assert_eq!(child_err, Err(DummyError));
println!("All rand_core::SeedableRng contract assertions passed successfully.");
}
Ursprungs-Seeder
anonym