I have a set of quiz game questions in a sql database (javascript and sqlite actually). The questions all have a difficulty level from 1 to 5, 5 being hardest. Here is a simplified visualization of the data...
+---------+--------------+ | id | difficulty | +---------+--------------+ | 1 | 1 | | 2 | 5 | | 3 | 2 | | 4 | 3 | | 5 | 2 | | 6 | 2 | | 7 | 4 | | 8 | 1 | | 9 | 5 | | 10 | 3 | +---------+--------------+
Now I can shuffle these fine in sql or code so they are in a random order with no repeats but I also want to have control over the way the difficulty field is ordered.
So for instance I could have a shuffled set of question where the difficulty level order looks like this...
1,1,5,2,3,3,2,2,2,4
This has several 'clumps' of difficulty, that's not what I want. The user playing the game would get several groups of the similarly difficult questions. An order like this would be better...
1,2,3,2,5,4,1,2,3,2
I want to ensure the questions are shuffled but without difficulty clumping. An even spread of difficulty where there are few, if any 'clumps'. Any help on the MySQL/javascript (or PHP) would be great.