Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

smartnathan's avatar

Quiz questions

I'm developing a quiz application, I want to be able to randomize the question such that two person taking the same quiz will not see similar questions. Tried doing that using laravel shuffle and also paginated it. Each time I make a request for the next question, it reorders the questions again making it difficult to answer the questions orderly. Please, is there a way i can randomize ones and maintain that same random state though the quiz process?

0 likes
6 replies
Sinnbeck's avatar

Yes absolutely. I just had the same issue myself recently. The second parameter for - >shuffle() is a seed. If it is the same, then the order will also be (but different to the users) . Put in the user id there are it should work

1 like
smartnathan's avatar

Thank you for your reply, please, I didn't really understand your response.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Sorry meant the first parameter. Like this

$shuffled = $questions->shuffle(auth()->user()->id);

Each user will get their questions shuffled the same way each time

2 likes
Sinnbeck's avatar

Happy to help. If you got it working, please remember to mark best answer

Please or to participate in this conversation.