From d1f7035c29c4969be536a30f4ff196a36a0543e1 Mon Sep 17 00:00:00 2001 From: Charlie DiGiovanna Date: Wed, 7 Jul 2021 15:54:44 -0400 Subject: [PATCH] Don't error out when shuffling empty arrays --- Example/Sources/Data Generation/Lorem.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Example/Sources/Data Generation/Lorem.swift b/Example/Sources/Data Generation/Lorem.swift index b368af71..b08e1d7d 100755 --- a/Example/Sources/Data Generation/Lorem.swift +++ b/Example/Sources/Data Generation/Lorem.swift @@ -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 {