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 55//!
66//! # Example
77//!
8- //! ```no_run
8+ //! ```
99//! use rand_core::{RngCore, SeedableRng};
1010//! use rand_core::block::{Generator, BlockRng};
1111//!
12- //! struct MyRngCore;
12+ //! struct MyRngCore {
13+ //! // Generator state ...
14+ //! # state: [u32; 8],
15+ //! }
1316//!
1417//! impl Generator for MyRngCore {
15- //! type Output = [u32; 16 ];
18+ //! type Output = [u32; 8 ];
1619//!
1720//! fn generate(&mut self, output: &mut Self::Output) {
18- //! unimplemented!()
21+ //! // Write a new block to output...
22+ //! # *output = self.state;
1923//! }
2024//! }
2125//!
2731//! impl SeedableRng for MyRng {
2832//! type Seed = [u8; 32];
2933//! fn from_seed(seed: Self::Seed) -> Self {
30- //! MyRng(BlockRng::new(MyRngCore))
34+ //! let core = MyRngCore {
35+ //! // ...
36+ //! # state: {
37+ //! # let mut buf = [0u32; 8];
38+ //! # rand_core::le::read_u32_into(&seed, &mut buf);
39+ //! # buf
40+ //! # }
41+ //! };
42+ //! MyRng(BlockRng::new(core))
3143//! }
3244//! }
3345//!
5062//!
5163//! let mut rng = MyRng::seed_from_u64(0);
5264//! println!("First value: {}", rng.next_u32());
65+ //! # assert_eq!(rng.next_u32(), 1171109249);
5366//! ```
5467//!
5568//! # ReseedingRng
You can’t perform that action at this time.
0 commit comments