mercredi 30 septembre 2015

How to compare random numbers in Swift

I’m a beginner in programming and playing around with the arc4random_uniform() function in Swift. The program I’m making so far generates a random number from 1-10 regenerated by a UIButton. However, I want the variable ’highest' that gets initialised to the random number to update if the next generated number is larger than the one currently held in it. For example the random number is 6 which is stored in highest and if the next number is 8 highest becomes 8. I don't know how to go about this. I have connected the UIButton to an IBAction function and have the following code:

    var randomValue = arc4random_uniform(11) + 1
    highest = Int(randomValue)

    if (Int(randomValue) < highest) {
        // Don’t know what to do
    }




Aucun commentaire:

Enregistrer un commentaire