-2

Before I say anything, please note that this is not a duplicate of: **

This Question

Because I have tried using all the answers from that question, but they all come up as errors because of the UINT32.

So, how can I generate a random number using arc4random but not making it the same number as last time?

JP Illanes
  • 3,665
  • 39
  • 56
  • check this link might be help you http://stackoverflow.com/questions/24132399/how-does-one-make-random-number-between-range-for-arc4random-uniform – Subin K Kuriakose Jun 10 '16 at 12:27
  • 1
    Hi and Welcome to Stack Overflow! Please take a few Minutes to review [How to Ask](https://stackoverflow.com/help/how-to-ask). Could you show what you have tried already and what your specific problems are? This makes it very easy for people to help you! – mhutter Jun 10 '16 at 12:28
  • Have a variable save the last random number. Then do a `while (newRandomNumber == oldRandomNumber) { newRandomNumber = generateRandomNumber(); }` – Zhang Jun 10 '16 at 12:30
  • 2
    Why does the accepted answer http://stackoverflow.com/a/27541269/1187415 not work for you? What code did you try and what errors exactly did you get? *"as errors because of the UINT32"* is too vague. – Martin R Jun 10 '16 at 12:33

1 Answers1

0

Here's a solution without using UINT32

var previousNumber: Int? // used in randomNumber()

func randomNumber() -> Int {
    var randomNumber = Int(arc4random_uniform(10))
    while previousNumber == randomNumber {
        randomNumber = Int(arc4random_uniform(10))
    }
    previousNumber = randomNumber
    return randomNumber
}
LuKenneth
  • 2,197
  • 2
  • 18
  • 41