#! 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], )