Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Randomly choosing from a set of alternatives with varying popularityby salva (Canon) |
on Mar 29, 2022 at 07:48 UTC ( [id://11142488]=note: print w/replies, xml ) | Need Help?? |
But I can't figure out how to favor those with the least popularity There are several ways to do that. Which one is the most appropriate is very dependent on your final problem. Anyway, I have not seen anybody propose an exponential solution, so let me do it. The idea is that every subject start with the same score, 1.0, for instance, and every time one of them gets a vote, you reduce its score multiplying it by a factor c such that 0 < c < 1. As in your particular case, you have already done a draw, you can calculate the current scores as $score{$k} = $c ** $votes{$k}. The only issue remaining is how to pick c. The key here is how much you want to penalize the popular ones.
In Section
Seekers of Perl Wisdom
|
|