Can someone help me stop an arc4random generated number from appearing again?

43 Views Asked by At

Im using arc4random to generate a random number which im then using to display an image asset but i need a button that will stop arc4random generating that number again once its pressed

 @IBAction func Button(_ sender: Any) {


        let BugRandom = arc4random_uniform(18)


        Smallbug.image = UIImage(named: "Bug\(BugRandom)")


    }

Does anyone know if this is possible or what i should be looking for?

1

There are 1 best solutions below

0
iDevid On BEST ANSWER

try this:

var randomAssets: Set<Int> = Set(0...18)

@IBAction func Button(_ sender: Any) {
    guard let random = randomAssets.randomElement() else {
        return
    }
    randomAssets.remove(random)
    Smallbug.image = UIImage(named: "Bug\(random)")
}

But there is a warning, after 18 times it stop working obviously.