print 'num of splits [positive integer]: '; my $splt = <>; print 'chance of going deeper [between 0 and 1]: '; my $chance = <>; my $avgOf = 1000000; my $sum = 0; for(my $n=0;$n<$avgOf:$n++) {$sum += dep();} print "avg depth is ".($sum / $avgOf)."\n"; exit; sub dep { if(rand() < $chance) {return 1+max(multiDep())}else {return 0;} } sub multiDep { my @keep; for($i=0;$i<$splt;$i++) {$keep[$i] = dep();} return @keep; } sub max { my $hi = shift; for my $v (@_) {if($v > $hi){$hi = $v;}} return $hi; }