Adam has asked for the wisdom of the Perl Monks concerning the following question:
Note that the distribution is reasonably smooth... but I want it to clump to the middle in either a bell curve or triangular fashion.my $pErr = 5; # for plus/minus 5. sub MakeP { my $p = $_[0]; $p -= $pErr; $p += int(rand() * 2 * ($pErr ++ 0.5)); return $p / 100 } #Test my @foo; push @foo, MakeP( 50 ) for 0 .. 20000; @foo = sort @foo; while ( @foo ) { my $next = shift @foo; my $count = 1; while ( @foo and $foo[0] == $next ) { ++$count; shift @foo } printf "%f\t%6d\n", $next, $count; }
sub MakeP { my $p = $_[0]; my $e = 1 + int( rand() * $pErr ); $p -= $e; $p += int( rand() * 2 * ( $e + 0.5 ) ); return $p / 100 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Curved Random Distribution
by fglock (Vicar) on Oct 18, 2005 at 16:33 UTC | |
by xdg (Monsignor) on Oct 18, 2005 at 17:50 UTC | |
|
Re: Curved Random Distribution
by Limbic~Region (Chancellor) on Oct 18, 2005 at 16:55 UTC | |
|
Re: Curved Random Distribution
by BrowserUk (Patriarch) on Oct 18, 2005 at 17:27 UTC | |
by Roy Johnson (Monsignor) on Oct 18, 2005 at 17:45 UTC | |
by BrowserUk (Patriarch) on Oct 18, 2005 at 20:01 UTC | |
|
Re: Curved Random Distribution
by blokhead (Monsignor) on Oct 18, 2005 at 17:08 UTC |