samedi 23 septembre 2017

How to generate random Strings without repeating any previous one?

My code already generates random Strings of an array when I press a button, but sometimes Strings get repeated. What do I have to do so that the String "Mango" only gets called again when all the other Strings where already called?

Example: "Mango", "Kiwi", "Banana", "Pineapple", "Melon", "Mango", "Kiwi",.....

Here is my code:

import UIKit

  var array = ["Mango", "Banana", "Apple","Kiwi", "Melon", "Pineapple"]

  let fruits = Int(arc4random_uniform(UInt32(array.count)))

  print(array[fruits])



Aucun commentaire:

Enregistrer un commentaire