I would like to have user click on a button to generate a ten-question quiz in the form of \"a +/- b = c\" where the values for a and b are from +10 to -10 and are randomly assi
Instead of using a NSDictionary
, use NSArray
if your keys are just numbers. You could then do
NSString *randomString = [array objectAtIndex:(arc4random() % [array count])];
to pick a random element.
However, I would really advice against looking it up in a plist if it's just different combinations of random numbers. Writing out all those combinations by hand is just a waste of time. That's what computers are for!
Old, but still relevant answer:
To generate a random number between -10
and 10
:
int a = (arc4random() % 21) - 10;
You could also make a function like this:
int randomIntegerInRange(int min, int max)
{
int range = max - min + 1;
return min + arc4random() % range;
}