objective c - How to create random numbers from 4 to 10 -
how can create random number within range? tried following code didn't accomplish task.
int fromnumber = 10; int tonumber = 30; int randomnumber = (arc4random()%(tonumber-fromnumber))+fromnumber;
there 7 numbers between 4 , 10 inclusive. arc4random_uniform() recommended on arc4random() purpose.
int randomnumber = arc4random_uniform(7) + 4
the more general case arc4random_uniform(upper_bound - lower_bound + 1) + lower_bound
.
Comments
Post a Comment