Random question type
The random question is not a real question but only a device to randomly choose a question from a category. The $question->questiontext field is abused as a flag: 1 means choose question from the cateogry and its subcategories, 0 means only use questions in the category itself.
When a new session is started for a random question then a question is chosen from the category. We need to make sure that no question is used more than once in the quiz. Therfore the following need to be excluded:
- All questions that are explicitly assigned to the quiz
- All questions that are already chosen by an other random question
- random questions
- wrapped questions
To do the first the question type uses an additional property $quiz->questionsinuse that holds a comma separated list of all questions used in the current quiz. To do the second the questiontype class has a property 'catrandoms' which is an array indexed by category id and by $question->questiontext. Each entry is a randomized array of questions in that category which can be used.
Response storage
The answer field for random questions come in two flavours:
- For responses stored by Moodle version 1.5 and later the answer field has the pattern random#-* where the # part is the numeric question id of the actual question shown in the quiz attempt and * represents the student response to that actual question.
- For responses stored by older Moodle versions - the answer field is simply the question id of the actual question. The student response to the actual question is stored in a separate record.
This means that prior to Moodle version 1.5, random questions needed two records for storing the response to a single question. From version 1.5 and later the question type random works like all the other question types in that it now only needs one record per question.
$question->options
The random question type does not have any options for $question->options.
$state->options
This has one property 'question' which is set to the fully instantiated question object for the randomly chosen question.