Anonymous user
Verify distribution uniformity/Naive: Difference between revisions
m
→{{header|REXX}}: changed/added whitespace and comments, centered the result.
(Added Elixir) |
m (→{{header|REXX}}: changed/added whitespace and comments, centered the result.) |
||
Line 1,202:
=={{header|REXX}}==
<lang rexx>/*REXX pgm simulates a
parse arg f t d s . /*obtain arguments (options)
if f=='' | f==',' then f='RANDOM' /*function
if t=='' | t==',' then t=1000000 /*times " " " " */
if d=='' | d==',' then d=1/2 /*delta% " " " " */
if s\=='' then call random ,,s /*use some RAND seed for
highDig=9 /*use this var for the highest digit. */
!.=0 /*
do j=1 for t /* [↓] perform a
if f=='RANDOM' then ?=random(0,highDig) /*random
else interpret '?='f"(0,"highDig')' /* user
!.?=!.?+1 /*bump the counter*/
end /*j*/ /* [↑] store trials ───► pigeonholes. */
/* [↓] compute the
g=t/(1+highDig) /*calculate
OK?='OK skewed' /*words to show "skewed" or if "OK".
w=max(8,length(t)) /*maximum length of
pad=left('',9) /*this is used for output indentation.
say pad 'digit' center("hits",w) ' skew ' "skew%" 'result' /*
say pad '─────' center('',w,'─') '──────' "─────" '──────' /*
/** [↑] show header
do k=0 to highDig /*process each of the possible
skew=g-!.k /*calculate the skew for the
skewPC=(1-(g-abs(skew))/g)*100 /* " " " percentage
ok=
say pad center(k,5) right(!.k,w) right(skew,6) format(skewPC,,3) ok
end /*k*/
say pad '─────' center('',w,'─') '──────'
y=5+1+w+1+6+1+6+1+6 /*the width. */
say pad center(" (with " t ' trials)',y)
say pad center(" (skewed when exceeds " d'%)',y) /*
/*stick a fork in it, we're all done. */</lang>
Execution note: quite a few runs were needed and the skew% lowered before a skewed result was obtained.
<br><br>
'''output''' when using the default inputs:
<pre>
digit hits skew skew% result
───── ──────── ────── ───── ──────
0
1 100226
2
3 100005
4
5 100011
6 100100
7
8
9
───── ──────── ────── ───── ──────
(with 1000000 trials)
|