We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 198e2e9 + aa4181c commit 033c253Copy full SHA for 033c253
src/distributions/uniform.rs
@@ -452,8 +452,9 @@ macro_rules! uniform_int_impl {
452
let ints_to_reject = (unsigned_max - range + 1) % range;
453
unsigned_max - ints_to_reject
454
} else {
455
- // conservative but fast approximation
456
- range << range.leading_zeros()
+ // conservative but fast approximation. `- 1` is necessary to allow the
+ // same comparison without bias.
457
+ (range << range.leading_zeros()).wrapping_sub(1)
458
};
459
460
loop {
0 commit comments