Skip to content

Commit 5978a5e

Browse files
committed
Add fn BlockRng::clear
1 parent 4f80e51 commit 5978a5e

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- `BlockRng::reconstruct` and `BlockRng::remaining_results` methods ([#36])
1212
- Re-export of `core::convert::Infallible` ([#56])
1313
- `BlockRng::word_offset` method ([#44])
14+
- `BlockRng::clear` method ([#69])
1415

1516
### Changed
1617
- Edition changed to 2024 and MSRV bumped to 1.85 ([rand#1668])

src/block.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ where
120120
}
121121
}
122122

123-
impl<W: Word + Default, const N: usize, G: Generator<Output = [W; N]>> BlockRng<G> {
123+
impl<W: Word, const N: usize, G: Generator<Output = [W; N]>> BlockRng<G> {
124124
/// Create a new `BlockRng` from an existing RNG implementing
125125
/// `Generator`. Results will be generated on first use.
126126
#[inline]
@@ -147,9 +147,7 @@ impl<W: Word + Default, const N: usize, G: Generator<Output = [W; N]>> BlockRng<
147147
None
148148
}
149149
}
150-
}
151150

152-
impl<W: Word, const N: usize, G: Generator<Output = [W; N]>> BlockRng<G> {
153151
/// Get the index into the result buffer.
154152
///
155153
/// If this is equal to or larger than the size of the result buffer then
@@ -166,6 +164,16 @@ impl<W: Word, const N: usize, G: Generator<Output = [W; N]>> BlockRng<G> {
166164
self.results[0] = W::from_usize(index);
167165
}
168166

167+
/// Clear the results buffer
168+
///
169+
/// This overwrites all bits of the results buffer, and thus may be useful
170+
/// in conjunction with [`zeroize`](https://docs.rs/zeroize/).
171+
#[inline]
172+
pub fn clear(&mut self) {
173+
self.results = [W::default(); N];
174+
self.results[0] = W::from_usize(N);
175+
}
176+
169177
/// Re-generate buffer contents, skipping the first `n` words
170178
///
171179
/// Existing buffer contents are discarded. A new set of results is

0 commit comments

Comments
 (0)