Seven-sided dice from five-sided dice: Difference between revisions

Content added Content deleted
m (Simplified)
No edit summary
Line 1,002: Line 1,002:
(t+2)\3
(t+2)\3
};</lang>
};</lang>
=={{header|Perl}}==
<lang perl>sub dice5 { 1+int rand(5) }

sub dice7 {
while(1) {
my $d7 = (5*dice5()+dice5()-6) % 8;
return $d7 if $d7;
}
}

my %count7;
my $n = 1000000;
$count7{dice7()}++ for 1..$n;
printf "%s: %5.2f%%\n", $_, 100*($count7{$_}/$n*7-1) for sort keys %count7;
</lang>
{{out}}
<pre>
1: 0.05%
2: 0.16%
3: -0.43%
4: 0.11%
5: 0.01%
6: -0.15%
7: 0.24%
</pre>


=={{header|Perl 6}}==
=={{header|Perl 6}}==