我尝试随机生成从 1 到 100 的数字。如何更改随机6 位数字?
注意:数字不能以 0(零)开头
随机 1 到 100 个代码
#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
}