gpt4 book ai didi

ios - 每次在测验中加载应用程序时随机化问题

转载 作者:行者123 更新时间:2023-11-29 03:17:37 25 4
gpt4 key购买 nike

每次有人运行我的应用程序时,我都试图将我的应用程序中的一组问题随机化。现在我有

-(void)Category1{

int QuestionSelected = rand() % 100;

switch (QuestionSelected) {
case 0:
QuestionText.text = [NSString stringWithFormat:@"Here is where my first question is"];
[Answer1 setTitle:@"First multiple choice" forState:UIControlStateNormal];
[Answer2 setTitle:@"Second multiple choice" forState:UIControlStateNormal];
[Answer3 setTitle:@"Third multiple choice" forState:UIControlStateNormal];
[Answer4 setTitle:@"Fourth multiple choice" forState:UIControlStateNormal];
Answer1Correct = YES;
CorrectAnswerDisplay.text = [NSString stringWithFormat:@"Right Answer"];
break;
case 1:
QuestionText.text = [NSString stringWithFormat:@"Here is where my second question is"];
[Answer1 setTitle:@"First multiple choice" forState:UIControlStateNormal];
[Answer2 setTitle:@"Second multiple choice" forState:UIControlStateNormal];
[Answer3 setTitle:@"Third multiple choice" forState:UIControlStateNormal];
[Answer4 setTitle:@"Fourth multiple choice" forState:UIControlStateNormal];
Answer1Correct = YES;
CorrectAnswerDisplay.text = [NSString stringWithFormat:@"Right Answer"];
break;

这一切都很好而且花花公子,但它只随机化了一次。所以它随机化了我在其中的所有 100 个问题,但是如果我关闭我的应用程序并从头开始再次运行它,它会以与之前相同的方式随机化,因此它运行的方式与之前处理相同问题的方式完全相同。有什么比我的 rand() 行更好的吗?

最佳答案

rand 需要通过调用 srand 来播种。更好的是,将 rand 的使用替换为 arc4randomarc4random_uniform。它不需要播种并且可以提供更好的结果。

关于ios - 每次在测验中加载应用程序时随机化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21503121/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com