Verify distribution uniformity/Naive: Difference between revisions

Content added Content deleted
(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: Line 1,559:
!.=0 /*initialize all possible random trials*/
!.=0 /*initialize all possible random trials*/
do times /* [↓] perform a bunch of trials. */
do times /* [↓] perform a bunch of trials. */
if func=='RANDOM' then ?=random(highDig) /*use RANDOM function.*/
if func=='RANDOM' then ?= random(highDig) /*use RANDOM function.*/
else interpret '?='func"(0,"highDig')' /* " specified " */
else interpret '?=' func "(0,"highDig')' /* " specified " */
!.?=!.? + 1 /*bump the invocation counter.*/
!.?= !.? + 1 /*bump the invocation counter.*/
end /*times*/ /* [↑] store trials ───► pigeonholes. */
end /*t*/ /* [↑] store trials ───► pigeonholes. */
/* [↓] compute the digit's skewness. */
/* [↓] compute the digit's skewness. */
g=times / (1 + highDig) /*calculate number of each digit throw.*/
g= times / (1 + highDig) /*calculate number of each digit throw.*/
w=max(9, length( commas(times) ) ) /*maximum length of number of trials.*/
w= max(9, length( commas(times) ) ) /*maximum length of number of trials.*/
pad=left('', 9) /*this is used for output indentation. */
pad= left('', 9) /*this is used for output indentation. */
say pad 'digit' center(" hits", w) ' skew ' "skew %" 'result' /*header. */
say pad 'digit' center(" hits", w) ' skew ' "skew %" 'result' /*header. */
say pad '─────' center('', w, '─') '──────' "──────" '──────' /*separator*/
say pad '─────' center('', w, '─') '──────' "──────" '──────' /*hdr sep.*/
/** [↑] show header and the separator.*/
/** [↑] show header and the separator.*/
do k=0 to highDig /*process each of the possible digits. */
do k=0 to highDig /*process each of the possible digits. */
skew=g - !.k /*calculate the skew for the digit. */
skew= g - !.k /*calculate the skew for the digit. */
skewPC=(1- (g-abs(skew)) / g) * 100 /* " " " percentage for dig*/
skewPC= (1 - (g - abs(skew)) / g) * 100 /* " " " percentage for dig*/
say pad center(k, 5) right( commas(!.k), w) right(skew, 6) ,
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)
right( format(skewPC, , 3), 6) center( word('ok skewed', 1+(skewPC>delta)), 6)
Line 1,578: Line 1,578:


say pad '─────' center('', w, '─') '──────' "─────" '──────' /*separator. */
say pad '─────' center('', w, '─') '──────' "─────" '──────' /*separator. */
y=5+1+w+1+6+1+6+1+6 /*the width. */
y= 5+1+w+1+6+1+6+1+6 /*width + seps*/
say pad center(" (with " commas(times) ' trials)' , y) /*# trials. */
say pad center(" (with " commas(times) ' trials)' , y) /*# trials. */
say pad center(" (skewed when exceeds " delta'%)' , y) /*skewed note.*/
say pad center(" (skewed when exceeds " delta'%)' , y) /*skewed note.*/
Line 1,584: Line 1,584:
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _=insert(',', _, jc); end; return _</lang>
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _=insert(',', _, jc); end; return _</lang>
{{out|output|text=&nbsp; when using the default inputs:}}
Execution note: &nbsp; quite a few runs were needed before a skewed result was obtained.
<br><br>
'''output''' when using the default inputs:
<pre>
<pre>
digit hits skew skew % result
digit hits skew skew % result