That is not how it works.
All the random question selection is done when the student clicks 'Start attempt'. If looking at the code helps you, the code for this is mod/quiz/startattempt.php -> quiz_prepare_and_start_new_attempt -> quiz_start_new_attempt -> \core_question\bank\random_question_loader