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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |