> rolling 0..99 will give alligator, 100..179 will give bear, etc., until 540..549 gives jellyfish.
Indeed, I missed the fact that N is an accumulated sum where all votes so far are subtracted. That wasn't obvious from the description and the code wasn't concise.
> As far as I know this is pretty much the standard approach
I'm curious to know how my other objection is handled. The order in a Perl hash is random, but fixed during a run. So this algorithm will be biased to some results.
Do you have a link to this "standard approach" discussing the distribution of picks?
My guess is the list must be sorted in ascending order. Or to be more precise that the choice over ascending or descending decides over popular vs unpopular.
> 0..99 will give alligator, 100..179 will give bear, etc., until 540..549 gives jellyfish.
FWIW, the results you give can only be reproduced with a descending sort.
> > > { alligator => 100, bear => 90, cat => 80, ... jellyfish => 10 }
(well almost s/179/189/ )
NB: the OP has uncommented the sort in his code.
> > > # sort { ($votes{$b} <=> $votes{$a}) } #unnecessary
|