I think you'll like this. Not only does it randomize your values for you, but it gives a visual display of the result so you can see the distribution. Change the weight to see how it affects things - larger numbers mean closer to $x, smaller means further, with 1 being classic bell curve.
use strict;
use warnings;
my ($x, $y, $weight, @r) = (5, 10, 2);
push @r, multirand($x, $y, $weight) for 1..10000;
display(\@r, 50);
sub multirand {
my ($x, $y, $weight) = @_;
return $x * $y ** (rand() ** $weight * (rand() > 0.5 ? 1 : -1));
}
sub display {
my ($r1, $max) = @_;
my (@r2, $skip, $i);
$skip = ($#$r1 + 1) / 40;
@r2 = sort { $a <=> $b } @$r1;
for ($i = 0; $i <= $#r2; $i += $skip) {
print 'x' x ($r2[$i] / $max * 80 + 0.5) . "\n";
}
}
Output:
x
x
x
xx
xx
xx
xxx
xxx
xxx
xxxx
xxxx
xxxxx
xxxxx
xxxxxx
xxxxxx
xxxxxxx
xxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxx
xxxxxxxxx
xxxxxxxxx
xxxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxxx
xxxxxxxxxxxxxx
xxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx