this question has answer here:
how generate random number in swift language can used in math, such addition. want able generate random number , add count have. example, how generate random number can add 1 to?
use arc4random_uniform()
function because generates uniform distribution.
the following line generates number 0-9.
var x = int(arc4random_uniform(10)) // cast int because function returns uint32 println(x) var sum = 10 + x println(sum)
Comments
Post a Comment