my $d = max_distance * ( 1 - log( rand(1000) ) / log( 1000 ) );