Optimal way to group items of varying quantities into sets of 5, with no duplicates in a set? Let’s say you are a trading card manufacturer and you have an inventory of cards that you want to divide into packs of 5 cards each, with no duplicates in a single pack.
There are 17 different types of cards (A through Q), and some are more rare than others.
You have the following inventory:

*

*25 of A

*50 of B

*50 of C

*50 of D

*50 of E

*100 of F

*100 of G

*100 of H

*100 of I

*200 of J

*200 of K

*200 of L

*200 of M

*400 of N

*400 of O

*400 of P

*400 of Q

This gives a total of 3025 cards, which is divisible by 5 but may not be when we impose the restriction of having no duplicates per pack.
Ideally, there would be some variety to the assortments, so packs would not contain simply A through E cards, or M through Q. There should be some randomness to them, or at least enough variation to seem random.
What is the cleanest way to approach this?
I have tried using a SQL database and assigning each individual card a random ID, then sorting by that ID and grabbing the first 5 rows with distinct types. This worked fairly well, but I was left with 15 cards of type L and 3 of type C, which was not ideal.
 A: A very non-random way would be:

*

*Make 400 packs with N, O, P, Q; fill 200 with M and 200 with L

*Make 100 packs with J,K,I,H and 100 with J,K,F,G; fill 50 each with B or C or D or E.

Unfortunately, this leaves us with the 25 A. Pick five of the packs without A and replace the $i$th Card of the $i$th pack with A. The five replaced cards can form another pack. Repeat this until all A are placed. Done. However, „more random/mixed“ would probably be nicer.
Alternative approach:
Take 35 from each of N,O,P,Q,J,K,L,M. For each of the ${8\choose 5}=56$ subsets, create a pack.
Repeat 5 times. This leaves you with 225 N-Q, 100 F-I, 50 B-E, 25 A and J-M. And we created 280 packs.
Take 35 from each of N,O,P,Q,F,G,H,I. Proceed as above, but repeat only twice. This leaves you with 155 N-Q, 50 B-E, 30 F-I, 25 A, J-M. And we created another 112 packs, 233 to go.
Take 35 from each of N,I,P,Q,B,C,D,E and proceed as above (without repetition). This leaves you with 120 N-Q, 30 F-I, 25 A, J-M, 15 B-E.
Take 20 of N,O,P,Q and create 20 packs by filling five with F, five with G, five with H, five with I. Now we have 100 N-Q, nine stacks of 25, four stacks of 15.
Take 45 of N,O,P,Q and create 45 packs, five each for each stack of size 25. Now we have 55 N-Q, nine stacks of 20, four stacks of 15.
Finish:
Now keep creating new packs by always picking from five of the highest heaps (but otherwise randomly chosen). After 36 rounds, this will reduce N-Q to 19, nine other stacks to 16, the rest stays at 15. After another five rounds, all 17 stacks have size 15.
From now on, stack sizes will never differ by more than 1, which guarantees that the last five items will be on five different stacks.
We could have started the „finish“ method earlier, but the „mix“ may be more appealing this way.
