> 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

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re^3: Randomly choosing from a set of alternatives with varying popularity by LanX
in thread Randomly choosing from a set of alternatives with varying popularity by ibm1620

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.