Liam Keeley Liam Keeley - 2 months ago 15
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] = ["


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] = ["