I have an array of structs that I randomise before a user starts the quiz. I want to get 3 of the questions randomly out of this array and put them into a new array. What is the best way I could do this?
Should I shuffle the array before selecting the random structs or is there a way to choose random structs?
So far the only way I can work out how to do this is to pre shuffle the array and then append the first 3 responses.
var learnersQuizQuestions =
[
questionInfo(question: "Question 0", questionNumber: 1, answer: true, explanation: "Explanation for Question 0"),
questionInfo(question: "Question 1", questionNumber: 2, answer: true, explanation: "Explanation for Question 1"),
questionInfo(question: "Question 2", questionNumber: 3, answer: true, explanation: "Explanation for Question 2"),
questionInfo(question: "Question 3", questionNumber: 4, answer: true, explanation: "Explanation for Question 3"),
questionInfo(question: "Question 4", questionNumber: 5, answer: true, explanation: "Explanation for Question 4")
]
Aucun commentaire:
Enregistrer un commentaire