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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -