I am confronted to this problem, here is an example :
A new day begins, I have 3 boxes that I have to paint. The boxes can be painted in either one of the following colors : red, green, yellow or blue
The statistics from the last few days show that : red is used for 43% of the boxes green is used for 7% of the boxes yellow is used for 21% of the boxes blue is used for 29% of the boxes
I want to be as consistent as possible with those percentages. How do I decide which colors to apply today ?
Well, it depends on what you mean by "as consistent as possible". The most natural candidate I can think of is minimum mean squared error - by which I mean, we want to minimize the average value of the square of the difference between the actual percentage and the intended percentage.
Ordinarily, if we weren't constrained to integers, this would be a calculus-based optimization problem, and I'd pull out Lagrange multipliers at this point. However, we're limited to integers - so the simplest solution is guess-and-check. A few tests provides the solution 1 red, 1 yellow, and 1 blue - the mean squared error in this case is (roughly) $\frac{(33 - 43)^2 + (7 - 0)^2 + (33 - 21)^2 + (33 - 29)^2}{4} = 77.25$. It's straightforward to show that we can't improve this - for example, if we change the number of red boxes, our error has to be at least $23^2/4 \approx 130 > 77.25$.
Note, however, that if you do this every day, the percentages won't match up - in the long run, painting one red, one yellow, and one blue will result in $33\%$ red, $0\%$ green, $33\%$ yellow, and $33\%$ blue. If you want a "protocol" that will result in keeping the percentages where they currently are, the best approach is to consider more days at once - in this case, we need $(43 + 7 + 21 + 29) / 3 \approx 34$ days. Over those $34$ days, paint the first $43$ boxes red, the next $7$ green, the next $21$ yellow, and the next $29$ blue.