Verify distribution uniformity/Naive: Difference between revisions
Content added Content deleted
(Verify distribution uniformity/Naive en FreeBASIC) |
m (→{{header|REXX}}: added whiteness and a subroutine.) |
||
Line 1,733: | Line 1,733: | ||
if func=='' | func=="," then func= 'RANDOM' /*function not specified? Use default.*/ |
if func=='' | func=="," then func= 'RANDOM' /*function not specified? Use default.*/ |
||
if times=='' | times=="," then times= 1000000 /*times " " " " */ |
if times=='' | times=="," then times= 1000000 /*times " " " " */ |
||
if delta=='' | delta=="," then |
if delta=='' | delta=="," then delta= 1/2 /*delta% " " " " */ |
||
if datatype(seed, 'W') then call random ,,seed /*use some RAND seed for repeatability.*/ |
if datatype(seed, 'W') then call random ,,seed /*use some RAND seed for repeatability.*/ |
||
highDig= |
highDig= 9 /*use this var for the highest digit. */ |
||
!.= |
!.= 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 /* |
end /*times*/ /* [↑] 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.*/ |
||
Line 1,747: | Line 1,747: | ||
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 sep /*display a separator line. */ |
|||
⚫ | |||
/** [↑] show header and the separator.*/ |
/** [↑] show header and the separator.*/ |
||
do k=0 to highDig |
do k=0 to highDig /*process each of the possible digits. */ |
||
skew= g - !.k |
skew= g - !.k /*calculate the skew for the digit. */ |
||
skewPC= (1 - (g - abs(skew)) / g) * 100 |
skewPC= (1 - (g - abs(skew)) / g) * 100 /* " " " percentage for dig*/ |
||
say pad center(k, 5) |
say pad center(k, 5) right( commas(!.k), w) right(skew, 6) , |
||
right( format(skewPC, , 3), 6) |
right( format(skewPC, , 3), 6) center( word('ok skewed', 1+(skewPC>delta)), 6) |
||
end /*k*/ |
end /*k*/ |
||
say sep /*display a separator line. */ |
|||
say pad '─────' center('', w, '─') '──────' "─────" '──────' /*separator. */ |
|||
y= 5+1+w+1+6+1+6+1+6 /*width + seps*/ |
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.*/ |
||
exit |
exit 0 /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _=insert(',', _, jc); end; return _ |
commas: parse arg _; do jc=length(_)-3 to 1 by -3; _=insert(',', _, jc); end; return _ |
||
⚫ | |||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |