Expand description
The BlockRngCore trait and implementation helpers
The BlockRngCore trait exists to assist in the implementation of RNGs
which generate a block of data in a cache instead of returning generated
values directly.
Usage of this trait is optional, but provides two advantages:
implementations only need to concern themselves with generation of the
block, not the various RngCore methods (especially fill_bytes, where
the optimal implementations are not trivial), and this allows
ReseedingRng (see rand crate) perform periodic
reseeding with very low overhead.
§Example
use rand_core::{RngCore, SeedableRng};
use rand_core::block::{BlockRngCore, BlockRng};
struct MyRngCore;
impl BlockRngCore for MyRngCore {
    type Item = u32;
    type Results = [u32; 16];
    fn generate(&mut self, results: &mut Self::Results) {
        unimplemented!()
    }
}
impl SeedableRng for MyRngCore {
    type Seed = [u8; 32];
    fn from_seed(seed: Self::Seed) -> Self {
        unimplemented!()
    }
}
// optionally, also implement CryptoBlockRng for MyRngCore
// Final RNG.
let mut rng = BlockRng::<MyRngCore>::seed_from_u64(0);
println!("First value: {}", rng.next_u32());Structs§
- Block
Rng  - A wrapper type implementing 
RngCorefor some type implementingBlockRngCorewithu32array buffer; i.e. this can be used to implement a full RNG from just ageneratefunction. - Block
Rng64  - A wrapper type implementing 
RngCorefor some type implementingBlockRngCorewithu64array buffer; i.e. this can be used to implement a full RNG from just ageneratefunction. 
Traits§
- Block
RngCore  - A trait for RNGs which do not generate random numbers individually, but in
blocks (typically 
[u32; N]). This technique is commonly used by cryptographic RNGs to improve performance. - Crypto
Block Rng  - A marker trait used to indicate that an 
RngCoreimplementation is supposed to be cryptographically secure.