http://www.perlmonks.org?node_id=158490


in reply to Rolling a biased die

my %bias = ( 1 => 3.1, 2 => 2.0234, 3 => 1.7, 4 => 1.542232, 5 => 1.321249563, 6 => 1.0142, ); my $sum = 0; while( my($k,$v) = each %bias ){ $rand = $k if rand($sum+=$v) < $v; }