in reply to custom random number generator

Improved and better tested:

#! perl -slw use strict; use Data::Dump qw[ pp ]; use Math::Random::MT qw[ rand srand ]; sub xrand { my( $x, $y ) = @_; my $lo = $x / $y; my $hi = $x * $y; if( rand() < 0.5 ) { my $root = sqrt( $hi - $x ); my $rv = rand( $root )**2 + $x; return $rv; } else { my $diff = $x - $lo; my $root = sqrt( $diff ); my $rv = ( $diff - rand( $root )**2 ) + $lo; return $rv; } } our $T //= 1000; our $X //= 10; our $Y //= 2; my $min = $X / $Y; my $max = $X * $Y; my( $loCount, $exactX, $hiCount ) = (0) x 3; my %dist; for ( 1 .. $T ) { my $rand = xrand( $X, $Y ); die 'Out of range' unless $rand >= $min and $rand <= $max; if( $rand < $X ) { ++$loCount; } elsif( $rand > $X ) { ++$hiCount; } else { ++$exactX; } ++$dist{ int( $rand *10 ) / 10 }; } pp \%dist; printf "After $T samples %f%% < %f%% < %f%%\n", $loCount * 100 / $T, $exactX *100 / $T, $hiCount * 100 / $T;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.