I tried random generate number from 1 to 100.How to change random 6 digits ?
Note :Numbers can not start with 0(zero)
Random from 1 to 100 codes
#import <UIKit/UIKit.h>
@interface RandomNumberGenViewController : UIViewController {
int number;
IBOutlet UILabel *label;
}
-(IBAction)generateNumber:(id)sender;
@end
@implementation RandomNumberGenViewController
-(IBAction)generateNumber:(id)sender {
number = (arc4random()%100)+1; //Generates Number from 1 to 100.
NSString *string = [NSString stringWithFormat:@"%i", number];
label.text = string
}
A random number with 6 digits would be:
int number = arc4random_uniform(1000000);
But that gives a number from 0 to 999,999. It sounds like you want a random number from 100,000 to 999,999. So do this:
int number = arc4random_uniform(900000) + 100000;