views:

88

answers:

2

Can I set a range of numbers when using arc4random()? For example 50-100 only.

+1  A: 
(arc4random() % (4))

will generate 0, 1, 2 or 3. Thus you could use:

(arc4random() % (51))

and merely add 50 to the result to get a range between 50 & 100

Run Loop
A: 
int fromNumber = 10;
int toNumber = 30;
int randomNumber = (arc4random()%(toNumber-fromNumber))+fromNumber;

Will generate randon number between 10 and 30, i.e.- 11,12,13,14......29

Vaibhav Saran