Skip to content

Commit

Permalink
Fix crash when shuffling empty deck,
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Jun 29, 2024
1 parent 5542832 commit 56a186f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/rs/src/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ impl Pcg32 {

pub fn shuffle<T>(&self, a: &mut [T]) {
let al = a.len() as u32;
for i in 0..al - 1 {
let j = self.upto(al - i);
a.swap(i as usize, i as usize + j as usize)
if al > 1 {
for i in 0..al - 1 {
let j = self.upto(al - i);
a.swap(i as usize, i as usize + j as usize)
}
}
}

Expand Down

0 comments on commit 56a186f

Please sign in to comment.