mercredi 3 août 2016

Stop the same random int coming up twice in a row [duplicate]

I'm trying to make it so when I click a button it generates a random int between 1 and 13 (inclusive), it doesn't give the same number twice in a row. Fairly new to swift btw

Ive looked at many other topics on here and still can't get it to work.

random int function:

func randomIntBetween(low:Int, high:Int) -> Int {
  let range = high - (low - 1)
  return (Int(arc4random()) % range) + (low - 1)
}

and the button:

    @IBAction func higher(sender: AnyObject) {
    //Random Number between 1-13
    numberLabel.text = String(randomIntBetween(2, high: 14))
    print(numberLabel.text)

Thanks




Aucun commentaire:

Enregistrer un commentaire