gpt4 book ai didi

iphone - 将索引分组的数组随机化(即 0-5 应该在一起)

转载 作者:行者123 更新时间:2023-11-28 20:21:10 25 4
gpt4 key购买 nike

我正在尝试创建一个多项选择考试类型的应用程序。我在 .txt 文件中有每个问题的问题、选择和答案,结构如下:

Question#1
choice A
choice B
choice C
choice D
Answer#1
Question#2
choice A
choice B
etc. etc.

目标是将其作为包含一百多个问题的题库。我设置了一个数组来读取所有这些信息。我需要随机化它,但我需要以一种保持问题#1 到答案#1 完整的方式进行(这样问题 2 及其下方的选择和答案可能会排在第一位)。这可能吗?

我们的想法是随机抽取一百个问题,然后将前 50 个问题(他们的选择和答案保持不变)用于“练习环节”。

非常感谢。

代码如下:

  if ([typeOfTest isEqualToString:@"SelectedExam"]) {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"SelectedExam" ofType:@"txt"];

NSString *SelectedExamBank = [[NSString alloc] initWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding error:NULL];

NSString* theBank = SelectedExamBank;


...

NSArray *multipleChoicePractice = [theBank componentsSeparatedByString:@"\n"];

//Calculating indexes while Question number would be in increments of 6
//(question 1 = index 0, question 2 = index 6, question 3 = index 12 etc)

choiceAindex = questionNumber + 1;
choiceBindex = questionNumber + 2;
choiceCindex = questionNumber + 3;
choiceDindex = questionNumber + 4;
theAnswer = [multipleChoicePractice objectAtIndex:answerChecker];

answerChecker = questionNumber + 5;

...

//q1 is the question and cA ... cD are choices

q1 = [multipleChoicePractice objectAtIndex:questionNumber];
cA = [multipleChoicePractice objectAtIndex:choiceAindex];
cB = [multipleChoicePractice objectAtIndex:choiceBindex];
cC = [multipleChoicePractice objectAtIndex:choiceCindex];
cD = [multipleChoicePractice objectAtIndex:choiceDindex];

最佳答案

如果没有看到代码,就很难找到解决方案。就个人而言,我建议创建一个新的 Question 类来保存问题、选择和答案。然后,您可以简单地将类的每个实例中的问题随机化,并保留一个问题数组。

关于iphone - 将索引分组的数组随机化(即 0-5 应该在一起),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6945691/

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