fixup rand for simulation target

TRNG doesn't exist in simulation - substitute it for a
deterministic PRNG when the simulation target is specified.
This commit is contained in:
bunnie 2025-09-20 22:13:16 +08:00
parent 4b99406277
commit 4f8169c3d9
2 changed files with 8 additions and 2 deletions

View file

@ -2,7 +2,11 @@
// SPDX-FileCopyrightText: 2024 bunnie <bunnie@kosagi.com>
// SPDX-License-Identifier: Apache-2.0
#[cfg(feature = "bao1x")]
#[cfg(all(feature = "bao1x", not(feature = "verilator-only")))]
#[path = "rand.rs"]
pub mod rand;
#[cfg(all(feature = "bao1x", feature = "verilator-only"))]
#[path = "rand_fake.rs"]
pub mod rand;
#[cfg(any(feature = "debug-print", feature = "print-panics"))]

View file

@ -24,7 +24,9 @@ static LOCAL_RNG_STATE: [AtomicU32; 8] = [
pub fn init() {}
/// This a fully deterministic PRNG that relies on Chacha8 for state evolution.
/// This a fully deterministic PRNG that relies on Chacha8 for state evolution. This is
/// used in verilator simulation environments.
#[cfg(feature = "verilator-only")]
pub fn get_u32() -> u32 {
// Local storage for the seed.
let mut seed = [0u8; 32];