Verify distribution uniformity/Naive: Difference between revisions

m
→‎{{header|REXX}}: added/changed whitespace and comments, elided an execution note, used a template for the output section.
(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) /*use RANDOM function.*/
else interpret '?=' func "(0,"highDig')' /* " specified " */
!.?= !.? + 1 /*bump the invocation counter.*/
end /*timest*/ /* [↑] store trials ───► pigeonholes. */
/* [↓] compute the digit's skewness. */
g= times / (1 + highDig) /*calculate number of each digit throw.*/
w= max(9, length( commas(times) ) ) /*maximum length of number of trials.*/
pad= left('', 9) /*this is used for output indentation. */
say pad 'digit' center(" hits", w) ' skew ' "skew %" 'result' /*header. */
say pad '─────' center('', w, '─') '──────' "──────" '──────' /*separatorhdr sep.*/
/** [↑] show header and the separator.*/
do k=0 to highDig /*process each of the possible digits. */
skew= g - !.k /*calculate the skew for the digit. */
skewPC= (1 - (g - abs(skew)) / g) * 100 /* " " " percentage for dig*/
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 /*the width. + seps*/
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>
'''{{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>
digit hits skew skew % result