Possible Duplicates:
Generating Random Numbers in Objective-C
What's the most optimal way to get a random floatingpoint number between floatA and floatB?
Hi,
I want to generate a random float number like
float scale = randFloat(0.5f, 2.0f);
How do I do this in objective-c?
Here is how you generate them :
// Get random value between 0 and 99
int x = arc4random() % 100;
// Get random number between 500 and 1000
int y = (arc4random() % 501) + 500);
You can easily extend this for any range you need.
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With