Anonymous user
Verify distribution uniformity/Naive: Difference between revisions
Verify distribution uniformity/Naive (view source)
Revision as of 21:36, 1 September 2018
, 5 years ago→{{header|REXX}}: added/changed whitespace and comments, elided an execution note, used a template for the output section.
SqrtNegInf (talk | contribs) (Added Perl example) |
m (→{{header|REXX}}: added/changed whitespace and comments, elided an execution note, used a template for the output section.) |
||
Line 1,559:
!.=0 /*initialize all possible random trials*/
do times /* [↓] perform a bunch of trials. */
if func=='RANDOM' then ?= random(highDig)
else interpret '?=' func "(0,"highDig')'
!.?= !.? + 1
end /*
/* [↓] compute the digit's skewness. */
g= times / (1 + highDig)
w= max(9, length( commas(times) ) )
pad= left('', 9)
say pad 'digit' center(" hits", w) ' skew ' "skew %" 'result' /*header.
say pad '─────' center('', w, '─') '──────' "──────" '──────' /*
/** [↑] show header and the separator.*/
do k=0 to highDig /*process each of the possible digits. */
skew= g - !.k
skewPC= (1 - (g - abs(skew)) / g) * 100
say pad center(k, 5) right( commas(!.k), w) right(skew, 6) ,
right( format(skewPC, , 3), 6) center( word('ok skewed', 1+(skewPC>delta)), 6)
Line 1,578:
say pad '─────' center('', w, '─') '──────' "─────" '──────' /*separator. */
y= 5+1+w+1+6+1+6+1+6
say pad center(" (with " commas(times) ' trials)' , y) /*# trials. */
say pad center(" (skewed when exceeds " delta'%)' , y) /*skewed note.*/
Line 1,584:
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _=insert(',', _, jc); end; return _</lang>
▲'''output''' when using the default inputs:
<pre>
digit hits skew skew % result
|