SQLFiddle Link
I\'ve got an SQLite database with a bunch of test/exam questions. Each question belongs to one question category.
Since it's sqlite (thus local): How slow would it be to just query until you have 5 answers and four different categories, dropping the duplicate category rows each iteration.
I think, if each category is equally represented, that it would be highly unlikely that you need more than 3 iterations which should still be below a second.
It's not algorithmically nice, but to me using random() in a SQL statement isn't algorithmically nice anyway.