lundi 20 août 2018

How to generate a single random item from array without a repeat?

Looking to show a random word from an array after each action, but not have it repeat itself. So if "blue" was chosen, it will not reappear.

@IBAction func ShowWord(_ sender: Any) 
{
    let array = ["blue","red","purple", "gold", "yellow", "orange","light blue", "green", "pink", "white", "black"]


    let RandomWordGen = Int(arc4random_uniform(UInt32(array.count)))
    randomWord?.text = array[RandomWordGen]




Aucun commentaire:

Enregistrer un commentaire