Jeff 'japhy' Pinyan wrote: > The extreme cases are the easy ones, though. What I'd like to see are > cases like: > > foo => 1 > bar => 2 > qux => 3 > baz => 4 > zip => 5 > > Once I know what the algorithm's outcome should be for something like > that, I think I can develop it.
Here's what I've come up with so far, which is extremely simple and seems to work reasonably well: 1. Compute total weight as sum of individual weights 2. For each item in the list compute an "interval" as (total weight) / (individual weight) 3. Write an entry for "weight" times, adding "interval" each time So, for the example above, total weight is 15. Start with foo: interval = 15 / 1 = 15. We need 1 foo, so: foo 15 bar: interval = 15 / 2 = 7.5. We need 2 bar's, so: bar 7.5 bar 15 qux: interval = 15 / 3 = 5. Need 3 qux, so: qux 5 qux 10 qux 15 Final list is: foo 15 bar 7.5 bar 15 qux 5 qux 10 qux 15 baz 3.75 baz 7.5 baz 11.25 baz 15 zip 3 zip 6 zip 9 zip 12 zip 15 Now sort the list by column 2, then by column 1: zip 3 baz 3.75 qux 5 zip 6 bar 7.5 baz 7.5 zip 9 qux 10 baz 11.25 zip 12 bar 15 baz 15 foo 15 qux 15 zip 15 Column 1 becomes the round-robin sequence, with the right number of each request, and farily evenly distributed. The sequence starts and ends with a "zip", so I have between 0 and 4 non-zip entries between pairs of zip's. 6 of every 15 requests should be a zip, so there should be an average of 1.5 non-zip's between zip's. Maybe I should could tweak my algorithm to better smooth the distribution of zip's. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>