Merge pull request #1598 from cd17822/patch-1

Don't error out when shuffling empty arrays
This commit is contained in:
Jakub Kašpar
2021-09-10 11:35:01 +02:00
committed by GitHub
@@ -223,6 +223,10 @@ public extension Array {
Shuffle the array in-place using the Fisher-Yates algorithm.
*/
mutating func shuffle() {
if count == 0 {
return
}
for i in 0..<(count - 1) {
let j = Int(arc4random_uniform(UInt32(count - i))) + i
if j != i {