我想生成一个介于 1 和 10 之间的随机数。当用户单击“下一步”按钮时,必须打印一个随机问题,并且问题不能重复。问题是有时这个问题会重复出现。任何人都可以帮助我或提供一些参考或教程吗?
- (IBAction)nextQuestion:(id)sender
{
NSInteger randomNum = arc4random() %10 ;
int countCounter= counter++;
[self.btnNext setTitle:@"Next" forState:UIControlStateNormal];
if(countCounter==4)
{
self.btnNext.hidden=YES;
self.btnQuizDone.hidden=NO;
}
switch ( arc4random()%10)
{
case 0:
{
NSLog(@"zero");
[lblQuestion setText:@"Q10:question number ten"];
}
break;
case 1:
{
NSLog(@"one");
[lblQuestion setText:@"Q2:question number two"];
}
break;
case 2:
{
NSLog(@"two");
[lblQuestion setText:@"Q6:question number six"];
}
break;
case 3:
{
NSLog(@"three");
[lblQuestion setText:@"Q5:question number five"];
}
break;
case 4:
{
NSLog(@"four");
[lblQuestion setText:@"Q3:question number three"];
}
break;
case 5:
{
NSLog(@"five");
[lblQuestion setText:@"Q9:question number nine"];
}
break;
case 6:
{
NSLog(@"six");
[lblQuestion setText:@"Q7:question number seven"];
}
break;
case 7:
{
NSLog(@"seven");
[lblQuestion setText:@"Q4:question number four"];
}
break;
case 8:
{
NSLog(@"eight");
[lblQuestion setText:@"Q1:question number one"];
}
break;
case 9:
{
NSLog(@"nine");
[lblQuestion setText:@"Q8:question number eight"];
}
break;
default:
break;
}
}