Skip to content

Commit 8492b75

Browse files
committed
Provide BlockRng64::index and BlockRng64::generate_and_set
1 parent 15bd401 commit 8492b75

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

rand_core/src/impls.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,28 @@ impl<R: BlockRngCore> BlockRng64<R> {
430430
&mut self.core
431431
}
432432

433-
// Reset the number of available results.
434-
// This will force a new set of results to be generated on next use.
433+
/// Get the index into the result buffer.
434+
///
435+
/// If this is equal to or larger than the size of the result buffer then
436+
/// the buffer is "empty" and `generate()` must be called to produce new
437+
/// results.
438+
pub fn index(&self) -> usize {
439+
self.index
440+
}
441+
442+
/// Reset the number of available results.
443+
/// This will force a new set of results to be generated on next use.
435444
pub fn reset(&mut self) {
436445
self.index = self.results.as_ref().len();
437446
}
447+
448+
/// Generate a new set of results immediately, setting the index to the
449+
/// given value.
450+
pub fn generate_and_set(&mut self, index: usize) {
451+
assert!(index < self.results.as_ref().len());
452+
self.core.generate(&mut self.results);
453+
self.index = index;
454+
}
438455
}
439456

440457
impl<R: BlockRngCore<Item=u64>> RngCore for BlockRng64<R>

0 commit comments

Comments
 (0)