Liam Keeley Liam Keeley - 1 month ago 6
Swift Question

Randomize an array

I need to randomize an array for an app I am trying to build in swift, and to test the function I created I put it into a playground with a sample array. I realize that this question has been asked here: How do I shuffle an array in Swift?
but I was just wondering why this specific way is not working. Here is my code:

import UIKit

var arrayOne : [String] = ["

Answer

It looks like there are a few issues.

First, it's a good idea to generally stay away from repeat-while. That paradigm is generally much more confusing than a simple while loop.

Second, your randomizer is leaving out the last item of the array.

Third, You're combining the usage of array and copyOfArray in an unpredictable way

try this:

var arrayOne : [String] = ["
Comments