《30天精通iPhone手机编程》-Day8-分歧解决器

        所谓分歧解决器也就是在一定的取值范围内取随机数,以下是两种形式的取随机数

//100以内的随机数
-(IBAction)oneToHundred {
	int rNumber = rand() % 100;
	result.text  = [[NSString alloc] initWithFormat:@"%d", rNumber];
}
//左轮枪,只有一颗子弹
-(IBAction)russianRoulette {
	int rNumber = rand() % 6;
	switch (rNumber) {
		case 0:
			result.text  = @"砰!!!";
			break;
		default:
			result.text = @"没事啦...";
			break;
	}
}


你可能感兴趣的:(《30天精通iPhone手机编程》-Day8-分歧解决器)