You are correct: in the ordinary way of throwing dice and adding their results, 2 dice yields a linear distribution, peaking in the middle.What I programmed was different: averaging the results of 2 random floats yields what appears to be a parabolic distribution, peaking in the middle of the range.

At this point, anybody reading who did well in probability and statistics is having a hearty laugh. Clearly it doesn't correspond well to dice, although it does give a practically useful probability distribution over a selected range (using normals, you can't be sure your results will be in your desired range).

Inspired to produce a more bell-like result and to more accurately simulate real-life dice-throwing, I came up with a new sub. The fewer sides the dice have, the more you can throw and sum to get a result in the desired range, so I made two-sided dice (which are usually called coins):

sub flip_coins { my ($low_end, $range) = @_; my $result = 0; $result += int(rand 2) for (2..$range); $low_end + $result; }
Results at the extreme ends of the range are very sparse, so I like the distribution of my original better.

The PerlMonk tr/// Advocate

In reply to Re^2: Fractional dice (more not fewer) by Roy Johnson
in thread Fractional dice by Roy Johnson

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.