File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change 1313//!
1414//! # Example
1515//!
16- //! ```no_run
16+ //! ```
1717//! use rand_core::{RngCore, SeedableRng};
1818//! use rand_core::block::{Generator, BlockRng};
1919//!
20- //! struct MyRngCore;
20+ //! struct MyRngCore {
21+ //! // Generator state ...
22+ //! # state: [u32; 8],
23+ //! }
2124//!
2225//! impl Generator for MyRngCore {
23- //! type Output = [u32; 16 ];
26+ //! type Output = [u32; 8 ];
2427//!
2528//! fn generate(&mut self, output: &mut Self::Output) {
26- //! unimplemented!()
29+ //! // Write a new block to output...
30+ //! # *output = self.state;
2731//! }
2832//! }
2933//!
3337//! impl SeedableRng for MyRng {
3438//! type Seed = [u8; 32];
3539//! fn from_seed(seed: Self::Seed) -> Self {
36- //! MyRng(BlockRng::new(MyRngCore))
40+ //! let core = MyRngCore {
41+ //! // ...
42+ //! # state: {
43+ //! # let mut buf = [0u32; 8];
44+ //! # rand_core::le::read_u32_into(&seed, &mut buf);
45+ //! # buf
46+ //! # }
47+ //! };
48+ //! MyRng(BlockRng::new(core))
3749//! }
3850//! }
3951//!
5870//!
5971//! let mut rng = MyRng::seed_from_u64(0);
6072//! println!("First value: {}", rng.next_u32());
73+ //! # assert_eq!(rng.next_u32(), 1171109249);
6174//! ```
6275//!
6376//! # ReseedingRng
You can’t perform that action at this time.
0 commit comments