Generate random number in range in iOS? [closed]
NSString *min = myMinTextField.text; //Get the current text from your minimum and maximum textfields.NSString *max = myMaxTextField.text;int randNum = rand() % ([max intValue] - [min intValue]) + [min intValue]; //create the random number.NSString *num = [NSString stringWithFormat:@"%d", randNum]; //Make the number into a string.[myLabel setText:num]; // Give your label the value of the string that contains the number.
Update:
It appears that it is probably better to use arc4random
as opposed to rand
you can see more about it here. Just replace all the rand
s with arc4random