I think this exhibits a pretty strong bias toward the lower numbers generated, and against the higher numbers. It may be pseudo random but the distribution is not close to flat.

use List::Util qw(sum); my @count = (0) x 20; for (1 .. 200000) { my @orderedRands = (grep{ rand(1) < 0.075 } map{ ($_) x 20 } 1 .. +20 )[0..19]; $count[$_]++ for grep {defined} @orderedRands; } my $sum = sum(@count); print "$_\t=>\t$count[$_]\t(", sprintf('%.2f', ($count[$_]/$sum)*100), + "% TTL)\n" for 1 .. 20;

...which produces...

1 => 300463 (7.53% TTL) 2 => 300337 (7.52% TTL) 3 => 300667 (7.53% TTL) 4 => 300333 (7.52% TTL) 5 => 300725 (7.53% TTL) 6 => 299081 (7.49% TTL) 7 => 299696 (7.51% TTL) 8 => 297134 (7.44% TTL) 9 => 289983 (7.26% TTL) 10 => 276352 (6.92% TTL) 11 => 252348 (6.32% TTL) 12 => 217016 (5.44% TTL) 13 => 175867 (4.41% TTL) 14 => 133708 (3.35% TTL) 15 => 96010 (2.40% TTL) 16 => 65012 (1.63% TTL) 17 => 41130 (1.03% TTL) 18 => 24485 (0.61% TTL) 19 => 14228 (0.36% TTL) 20 => 7685 (0.19% TTL)

...and that is with adding the filtering-out of undefined values that found their way into @orderedRands.

I hope my adaptation of your algorithm didn't miss an important nuance.


Dave


In reply to Re^2: random #s by davido
in thread random #s by cboPerl

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.