#! perl -slw use strict; use Math::Random::MT qw[ rand ]; use constant LIMIT => 1 / 40000; $|++; my( $aveTrue, $aveFalse ) = (0,0); while( 1 ) { my( $true, $false ) = (0,0); for( 1 .. 40000 ) { if( rand() < LIMIT ) { ++$true; } else { ++$false; } } $aveTrue += $true; $aveFalse += $false; printf "\rThis time: $true/$false; Accumulate ratio: %f / 40000", $aveTrue / ( $aveFalse / 40000 ); } __END__ C:\test>1001701.pl This time: 0/40000; Accumulate ratio: 0.995570 / 40000