Skip to content

Commit d1f7035

Browse files
authored
Don't error out when shuffling empty arrays
1 parent c33d028 commit d1f7035

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Example/Sources/Data Generation/Lorem.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ public extension Array {
223223
Shuffle the array in-place using the Fisher-Yates algorithm.
224224
*/
225225
mutating func shuffle() {
226+
if count == 0 {
227+
return
228+
}
229+
226230
for i in 0..<(count - 1) {
227231
let j = Int(arc4random_uniform(UInt32(count - i))) + i
228232
if j != i {

0 commit comments

Comments
 (0)