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

the julia implementation
(→‎{{header|jq}}: assumption)
(the julia implementation)
Line 1,277:
Using a two-sided χ2-test with seven degrees of freedom (1.69, 16.013), it is reasonable to conclude that
this is consistent with the die being fair.
</pre>
 
=={{header|Julia}}==
 
<syntaxhighlight lang="julia">
using Random: seed!
seed!(1234) # for reproducibility
 
dice5() = rand(1:5)
 
function dice7()
while true
a = dice5()
b = dice5()
c = a + 5(b - 1)
if c <= 21
return mod1(c, 7)
end
end
end
 
rolls = (dice7() for i in 1:100000)
roll_counts = Dict{Int,Int}()
for roll in rolls
roll_counts[roll] = get(roll_counts, roll, 0) + 1
end
foreach(println, sort(roll_counts))
 
</syntaxhighlight>
 
Output:
<pre>
1 => 14530
2 => 13872
3 => 14422
4 => 14425
5 => 14323
6 => 14315
7 => 14113
</pre>
 
6

edits