True Random Xcode

后端 未结 4 982
耶瑟儿~
耶瑟儿~ 2021-01-26 02:01

I\'m currently making a quiz app. When a user starts the quiz random questions show up like you would expect from a quiz app. The problem is, it is not quite random. It does sho

4条回答
  •  悲&欢浪女
    2021-01-26 02:38

    The idea is to use each question once until all questions have been used.

    Sample code. Note that the questionIndex does not repeat.

    // Setup
    int questionCount = 10; // real number of questions
    NSMutableArray *questionIndexes = [NSMutableArray array];
    for (int i=0; i

    NSLog output:
    arrayIndex: 9, questionIndex: 9
    arrayIndex: 5, questionIndex: 5
    arrayIndex: 5, questionIndex: 6
    arrayIndex: 3, questionIndex: 3
    arrayIndex: 3, questionIndex: 4
    arrayIndex: 4, questionIndex: 8
    arrayIndex: 2, questionIndex: 2
    arrayIndex: 0, questionIndex: 0
    arrayIndex: 1, questionIndex: 7
    arrayIndex: 0, questionIndex: 1

提交回复
热议问题