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

m
(the julia implementation)
 
(5 intermediate revisions by 3 users not shown)
Line 566:
}
println(bins.snapshot())</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
func dice5 .
return randint 5
.
func dice25 .
return (dice5 - 1) * 5 + dice5
.
func dice7a .
return dice25 mod1 7
.
func dice7b .
repeat
h = dice25
until h <= 21
.
return h mod1 7
.
numfmt 3 0
n = 1000000
len dist[] 7
#
proc checkdist . .
for i to len dist[]
h = dist[i] / n * 7
if abs (h - 1) > 0.01
bad = 1
.
dist[i] = 0
print h
.
if bad = 1
print "-> not uniform"
else
print "-> uniform"
.
.
#
for i to n
dist[dice7a] += 1
.
checkdist
#
print ""
for i to n
dist[dice7b] += 1
.
checkdist
</syntaxhighlight>
 
{{out}}
<pre>
1.122
1.118
1.121
1.117
0.840
0.842
0.840
-> not uniform
 
0.996
1.003
1.001
0.997
1.004
0.998
1.001
-> uniform
</pre>
 
=={{header|Elixir}}==
Line 2,103 ⟶ 2,174:
7 6 3 5 2 2 7 1 2 7 3 7 4 4 4 2 3 2 6 1
</pre>
 
=={{header|RPL}}==
<code>UNIF?</code> is defined at [[Verify distribution uniformity/Naive#RPL|Verify distribution uniformity/Naive]]
{{works with|Halcyon Calc|4.2.7}}
≪ ≪ RAND 5 * CEIL ≫ → dice5
≪ '''WHILE'''
dice5 EVAL 5 *
dice5 EVAL 6 - +
DUP 21 ≥
'''REPEAT''' DROP '''END'''
7 MOD 1 +
≫ ≫ '<span style="color:blue">DICE7</span>' STO
 
≪ <span style="color:blue">DICE7</span> ≫ 100000 .1 <span style="color:blue">UNIF?</span>
{{out}}
<pre>
1: [ 14557 14245 14255 14400 14224 14151 14168 ]
</pre>
Watchdog timer limits the loop to 100,000 items.
 
=={{header|Ruby}}==
Line 2,420 ⟶ 2,510:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "random" for Random
import "./sort" for Sort
import "./fmt" for Fmt
 
var r = Random.new()
1,983

edits