I made a variable using arc4random this way:
var a = Int(arc4random_uniform(25))
I want a
to be between 0 and 24.
Sometimes it works fine, but sometimes it gives a HUGE value with about 20 characters!
What causes this and how can I fix it?
I made a variable using arc4random this way:
var a = Int(arc4random_uniform(25))
I want a
to be between 0 and 24.
Sometimes it works fine, but sometimes it gives a HUGE value with about 20 characters!
What causes this and how can I fix it?
Swift can be a little unpredictable about how it infers variable types.
Try explicitly type casting both the variable a and the constant (25). I tested this code and it worked fine: