I am writing a program that has to select 10 items randomly from a database . the criteria is that its type should be based on users choice .
So if the user chooses type 1
the program has to choose 10 items
of type 1
if the user chooses type 1 and 2
the program has to choose 5 items
from type 1
and 5 items
from type 2
if the user chooses type 1 , 2 and 4
the program has to choose 3 items
for each type
and one of the types must have and extra item
to get 10 items and which type gets an extra question has to be random.
So This has to be done for N number of types that the user can choose from .
Any suggestions on the way this can be achieved ?
By the way I am trying to build a Random generator so the result has to be random each time.
Ps: I am coding in python , but any language code is fine .
PS: I am already able to select items using SQL WHERE Clause , That is not the real problem.
the problem is once I have gotten items of each of the selected types , I have to select exactly 10 items with the above proportions , (i.e) : if 4 types are chosen 2 items for each type and and exactly 2 extra items in any two of the types .