Fix underflow in shuffle with empty list

This commit is contained in:
Paul Hauner 2018-10-22 05:24:13 +11:00
parent bdb5c45e60
commit db735a598f
No known key found for this signature in database
GPG Key ID: 303E4494BB28068C

View File

@ -34,7 +34,7 @@ pub fn shuffle<T>(
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 j = rng.rand_range(n as u32) as usize + i;
list.swap(i, j);