From 0cee068526bb4f93572884bdf9e99811fd847f22 Mon Sep 17 00:00:00 2001 From: Mark Wainwright Date: Fri, 6 Jan 2023 14:57:06 +0000 Subject: [PATCH] Added a comment re possible further optimization --- src/seq/increasing_uniform.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/seq/increasing_uniform.rs b/src/seq/increasing_uniform.rs index 160a181f6c..d4b6f1e0d1 100644 --- a/src/seq/increasing_uniform.rs +++ b/src/seq/increasing_uniform.rs @@ -32,6 +32,12 @@ impl IncreasingUniform { pub fn next_index(&mut self) -> usize { let next_n = self.n + 1; + // There's room for further optimisation here: + // gen_range uses rejection sampling (or other method; see #1196) to avoid bias. + // When the initial sample is biased for range 0..bound + // it may still be viable to use for a smaller bound + // (especially if small biases are considered acceptable). + let next_chunk_remaining = self.chunk_remaining.checked_sub(1).unwrap_or_else(|| { // If the chunk is empty, generate a new chunk let (bound, remaining) = calculate_bound_u32(next_n);