Anonymous user
Verify distribution uniformity/Naive: Difference between revisions
Verify distribution uniformity/Naive (view source)
Revision as of 15:05, 22 September 2017
, 6 years ago→{{header|REXX}}: changed comments and whitespace, changed some variable names to be more descriptive, added commas to output for easier reading the results.
No edit summary |
(→{{header|REXX}}: changed comments and whitespace, changed some variable names to be more descriptive, added commas to output for easier reading the results.) |
||
Line 1,459:
=={{header|REXX}}==
<lang rexx>/*REXX program simulates a number of trials of a random digit and show it's skew %. */
parse arg
if
if
if
if
highDig=9 /*use this var for the highest digit. */
!.=0 /*initialize all possible random trials*/
do
if
else interpret '?='
!.?=!.? +
end /*t*/ /* [↑] store trials ───► pigeonholes. */
/* [↓] compute the digit's skewness. */
g=
pad=left('', 9) /*this is used for output indentation. */
say pad
say pad
/** [↑] 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 /* " " " percentage for dig*/
end /*k*/
say pad '─────' center('', w, '─') '──────' "─────" '──────'
y=5+1+w+1+6+1+6+1+6 /*the width. */
say pad center(" (with " commas(times)
say pad center(" (skewed when exceeds "
/*──────────────────────────────────────────────────────────────────────────────────────*/
Execution note: quite a few runs were needed and the skew'''%''' lowered before a skewed result was obtained.▼
commas: procedure; parse arg _; n=_'.9'; #=123456789
e=verify(n, #'0', , verify(n, #"0.",'M') ) - 4
do j=e to verify(n, #, "M") by -3; _=insert(',', _, j); end; return _</lang>
▲Execution note: quite a few runs were needed
<br><br>
'''output''' when using the default inputs:
<pre>
digit hits skew skew % result
─────
0
1
2
3
4
5
6
7
8 100,488
9
─────
(skewed when exceeds 0.5%)
</pre>
|