Merge pull request #60 from sigp/shuffle_underflow
Fix underflow in shuffle with empty list
This commit is contained in:
commit
9bd092e419
@ -34,7 +34,7 @@ pub fn shuffle<T>(
|
|||||||
return Ok(list);
|
return Ok(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..(list.len() - 1) {
|
for i in 0..(list.len().saturating_sub(1)) {
|
||||||
let n = list.len() - i;
|
let n = list.len() - i;
|
||||||
let j = rng.rand_range(n as u32) as usize + i;
|
let j = rng.rand_range(n as u32) as usize + i;
|
||||||
list.swap(i, j);
|
list.swap(i, j);
|
||||||
|
Loading…
Reference in New Issue
Block a user