Expand description
§xoroshiro256** PRNG (fast, non-cryptographic)
A tiny, fast implementation of xoroshiro256 without bit waste, intended for simulations,
games, and other deterministic workloads. This generator is not
cryptographically secure. If you need CSPRNG, enable the "crypto"
feature and use CryptoRng256 (ChaCha20).
§Features
rand_core— implementsrand_core::RngCoreandSeedableRng.serde— enablesSerialize/DeserializeforXoroshiro256State.crypto— providesCryptoRng256(ChaCha20) for cryptographic use.
§Examples
§Fast deterministic numbers (no features required)
use xoroshiro256_full::Xoroshiro256State;
let mut rng = Xoroshiro256State::init([1, 2, 3, 4], 4);
let x = rng.next_u64(); // fast, deterministic§Integrate with rand ecosystem (enable rand_core)
use rand_core::{RngCore, SeedableRng};
use xoroshiro256_full::Xoroshiro256State;
let mut rng = Xoroshiro256State::seed_from_u64(42);
let _ = rng.next_u32();§Cryptographically secure RNG (enable crypto)
use xoroshiro256_full::CryptoRng256;
let mut crng = CryptoRng256::from_os();
let x = crng.next_u64();§Notes
- This crate uses wrapping arithmetic to match the original reference.
- Endianness: byte conversions use little-endian (
to_le_bytes).
§No bit waste (implementation detail)
When the rand_core feature is enabled, this implementation avoids bit waste in two places:
next_u32()caches the unused 32 bits from a generatedu64and returns them on the next call.fill_bytes()caches any unused tail bytes (up to 7) from a generatedu64and uses them at the start of the next call.
These caches are not part of the algorithmic state and are skipped during serde serialization; only the 256-bit xoroshiro state is serialized.
Structs§
- Crypto
Rng256 - Cryptographically secure RNG wrapper (ChaCha20).
- Xoroshiro256
State - Internal state for xoroshiro256** (4 × 64-bit words).