I'm curious why the order in which the hash is traversed would matter at all. I tried both sorting and shuffling the hash keys on each roll of the dice and the overall distribution of choices remained (approximately) the same. Seems to me that as long as the percentage of votes remains the same, the randomness of the dice ensures that over time it'll land on each animal that percent of the time.

Example when 'popular' shuffles the candidate list each time. (Note that now the distribution of votes isn't linear.)

==> alligator:1000 bear: 900 cat: 800 dog: 700 elephant: 600 fox: 100 +giraffe: 10 hippo: 1 (Total votes: 4111) POP alligator: 977 bear: 933 cat: 804 dog: 720 elephant: 571 fox: 99 +giraffe: 6 hippo: 1 (Total votes: 4111)
I also tried sorting the candidates in both ascending and descending order. Same result.

In reply to Re^5: Randomly choosing from a set of alternatives with varying popularity by ibm1620
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.