Skip to content

Commit 033c253

Browse files
authored
Merge pull request #662 from TheIronBorn/patch-10
fix #661
2 parents 198e2e9 + aa4181c commit 033c253

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/distributions/uniform.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,9 @@ macro_rules! uniform_int_impl {
452452
let ints_to_reject = (unsigned_max - range + 1) % range;
453453
unsigned_max - ints_to_reject
454454
} else {
455-
// conservative but fast approximation
456-
range << range.leading_zeros()
455+
// conservative but fast approximation. `- 1` is necessary to allow the
456+
// same comparison without bias.
457+
(range << range.leading_zeros()).wrapping_sub(1)
457458
};
458459

459460
loop {

0 commit comments

Comments
 (0)