Anonymous user
Verify distribution uniformity/Naive: Difference between revisions
m
→{{header|REXX}}: added whiteness and a subroutine.
(Verify distribution uniformity/Naive en FreeBASIC) |
m (→{{header|REXX}}: added whiteness and a subroutine.) |
||
Line 1,733:
if func=='' | func=="," then func= 'RANDOM' /*function not specified? Use default.*/
if times=='' | times=="," then times= 1000000 /*times " " " " */
if delta=='' | delta=="," then
if datatype(seed, 'W') then call random ,,seed /*use some RAND seed for repeatability.*/
highDig=
!.=
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 /*
/* [↓] compute the digit's skewness. */
g= times / (1 + highDig) /*calculate number of each digit throw.*/
Line 1,747:
pad= left('', 9) /*this is used for output indentation. */
say pad 'digit' center(" hits", w) ' skew ' "skew %" 'result' /*header. */
say sep /*display a separator line. */
say pad '─────' center('', w, '─') '──────' "──────" '──────' /*hdr sep.*/▼
/** [↑] show header and the separator.*/
do k=0 to highDig
skew= g - !.k
skewPC= (1 - (g - abs(skew)) / g) * 100
say pad center(k, 5)
right( format(skewPC, , 3), 6)
end /*k*/
say sep /*display a separator line. */
y= 5+1+w+1+6+1+6+1+6 /*width + seps*/
say pad center(" (with " commas(times) ' trials)' , y) /*# trials. */
say pad center(" (skewed when exceeds " delta'%)' , y) /*skewed note.*/
exit
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _=insert(',', _, jc); end; return _
{{out|output|text= when using the default inputs:}}
<pre>
|