mercredi 21 décembre 2016

How to create a randomized if else statement swift 3

The following code runs like a traffic light. Red -> Yellow -> Green. How can my code by written so that when "else if timerInt == 0 {" comes either r.png or yellow.png come up. Basically a coin is flipped and either r or yellow will show up. But the chances are equal and its always random. Thanks

   timerInt -= 1
    if timerInt == 2{
        light.image = UIImage(named: "r.png")
    } else if timerInt == 1 {
        light.image = UIImage(named: "yellow.png")
    } else if timerInt == 0 {
        light.image = UIImage(named: "g.png")
     }




Aucun commentaire:

Enregistrer un commentaire