Built an iPhone app that generates a random number to a label when a button is pressed.
Simple, just to learn new skills.
it works fine, but any value i put doesn't seem to limit the value of the random number generated. it's always 9 digits.
-(IBAction)genRandnum:(id)sender {
NSNumber *randomNumber = [NSNumber numberWithInt: (arc4random() % 5) + 1];
NSNumber *randomLabeltxt = [[NSString alloc] initWithFormat:@"It worked!", randomNumber];
randLabel.text = [NSString stringWithFormat: @"%d", randomLabeltxt];
[randomLabeltxt release];
}
As you can see, i've put 5 in after the % sign, but it generates 9 digit numbers. What am doing wrong?