You need to deal out a stream of items one at a time in proportions.
You could use a round robin list. A,B,C,A,B,A,B,C,A,B,A,B,C
This idea uses a bank of numerical controlled oscillators.
You have an array of buckets, and these accumulate fill in the required proportions.
You have a bucket for each destination.
OnItemRecieved{ Add requiredProportionToBuckets() // Pick distination FindBucketWithMostFill() // Look for bucket with most fill, Thats the destination, and empty it. DeliverItemToDestination( FindBucketWithMostFill() ) EmptyFullestBucket( FindBucketWithMostFill() ) }
Add a leaky bucket on the output. If running
Empty the bucket if picked, but by more than the sum of proportions.
If Leaky Bucket running subtract Add an amount for Time
You could measure the rate of OnItem Requests.
Could you have a bucket that backed off traffic, like the fairground penny fall profit.
Could you have a bucket that leaked.
OnItemReceived() - add proportions each item. OnLeak() - add proportions on timer tick, so they get picked.
When an Item is picked, subtract the sum of proportions from the bucket.
Should each bucket also have a time component? Should the bucket record when it was last emptied? If picked too often should it buffer and back off.
http://www.dougrice.plus.com/Erlangs/loadShareTry.htm
http://www.dougrice.plus.com/Erlangs/loadShare.htm
http://www.dougrice.plus.com/Erlangs/loadShareMidi.htm