#! perl -slw use strict; use Data::Dump qw[ pp ]; $Data::Dump::WIDTH = 300; my( @counts, @ns ); for( 1 .. 1e6 ) { my @orderedRands = grep{ rand(1) < 0.05 } map{ ($_) x 20 } 1 .. 20; ++$ns[ @orderedRands ]; ++$counts[ $_ ] for @orderedRands; } pp \@counts, \@ns; #### [undef, 999508, 999959, 1000278, 1002083, 999969, 1001388, 1002007, 999127, 1000314, 1001289, 1000014, 999255, 1000929, 1001682, 1000862, 998954, 1002277, 999569, 1000337, 999569] #### [undef, undef, undef, 2, 7, 33, 157, 398, 1041, 2437, 5333, 9541, 16508, 25675, 37569, 50824, 64506, 76623, 85656, 90711, 91374, 86560, 78584, 68077, 56808, 44695, 33849, 24855, 17439, 11775, 7601, 4708, 2839, 1690, 981, 568, 290, 137, 74, 41, 12, 9, 11, 1, 1], ) #### [undef, 1495533, 1499609, 1498974, 1499522, 1501930, 1501314, 1499981, 1501222, 1499646, 1500600, 1500068, 1500915, 1498017, 1500384, 1501031, 1498257, 1500431, 1501058, 1498359, 1500716] [undef, undef, undef, undef, undef, undef, undef, undef, undef, 2, 12, 31, 75, 170, 373, 768, 1568, 2718, 4802, 7795, 12096, 17806, 24879, 32813, 41477, 51438, 59539, 66763, 72668, 74986, 75575, 73039, 68515, 61653, 53917, 46112, 37751, 30042, 23138, 17536, 12842, 9196, 6284, 4298, 2803, 1748, 1053, 721, 429, 253, 156, 80, 43, 17, 8, 8, 2, undef, 1, undef, 1], #### #! perl -slw use strict; use Data::Dump qw[ pp ]; $Data::Dump::WIDTH = 300; my( @counts, @ns ); for( 1 .. 1e6 ) { my @orderedRands = grep{ rand(1) < 0.05 } map{ ($_) x 20 } 1 .. 20; while( @orderedRands != 20 ) { @orderedRands = grep{ rand(1) < 0.05 } map{ ($_) x 20 } 1 .. 20; } ++$ns[ @orderedRands ]; ++$counts[ $_ ] for @orderedRands; } pp \@counts, \@ns; __END__ C:\test>junk62 ( [undef, 1000652, 999987, 1000022, 999969, 999146, 1000961, 1000568, 1000129, 1000725, 999884, 999509, 999756, 1000538, 999763, 1000708, 1000826, 999799, 998778, 998714, 999566], [undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, 1000000], )