I have a set of objects, and each object has (let's say) a
color. Given a distribution such as:
red : 50% green : 30% blue : 20%
I need to produce an N-length array of objects with a color distribution as close to this as possible. It is possible that the length of the original list is smaller than N, so duplicates may be required.
Is there an efficient algorithm that might be suited for this kind of task? I imagine there is, but I'm lacking the terminology to find it.