##Using shuffledShuffled I suppose you just need to get 5 different random pool ball names from your ballArray. So you don't need to generate any random numbers. Just in buttonPressed create a constant from shuffled ballArray
let shuffledBallArray = ballArray.shuffled() now just set images like this:
poolBallView1.image = UIImage(named: shuffledBallArray[0]) poolBallView2.image = UIImage(named: shuffledBallArray[1]) ... So your buttonPressed action should look like this:
@IBAction func buttonPressed(_ sender: UIButton) { let shuffledBallArray = ballArray.shuffled() poolBallView1.image = UIImage(named: shuffledBallArray[0]) poolBallView2.image = UIImage(named: shuffledBallArray[1]) poolBallView3.image = UIImage(named: shuffledBallArray[2]) poolBallView4.image = UIImage(named: shuffledBallArray[3]) poolBallView5.image = UIImage(named: shuffledBallArray[4]) } ##Creating unique random numbersUnique Random Numbers Alternatively you can create function which gives you 5 unique random numbers
func generateNumbers(repetitions: Int, maxValue: Int) -> [Int] { var numbers = [Int]() for _ in 1...repetitions { var n: Int repeat { n = Int.random(in: 1...maxValue) } while numbers.contains(n) numbers.append(n) } return numbers } and in buttonPressed just create constant for this array of random numbers and set images without saving any image names somewhere in ballArray with hardcoded 50 names
@IBAction func buttonPressed(_ sender: UIButton) { let randomNumbers = generateNumbers(repetitions: 5, maxValue: 50) poolBallView1.image = UIImage(named: "poolBall\(randomNumbers[0])") poolBallView2.image = UIImage(named: "poolBall\(randomNumbers[1])") poolBallView3.image = UIImage(named: "poolBall\(randomNumbers[2])") poolBallView4.image = UIImage(named: "poolBall\(randomNumbers[3])") poolBallView5.image = UIImage(named: "poolBall\(randomNumbers[4])") }