Anonymous user
Unbias a random generator: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, changed indentations.
No edit summary |
m (→{{header|REXX}}: added/changed comments and whitespace, changed indentations.) |
||
Line 1,402:
=={{header|REXX}}==
<lang rexx>/*REXX program generates unbiased random numbers and displays the results
parse arg # R seed . /*get optional parameters from the CL. */
if #=='' | #==
if R=='' | R==
if datatype(seed
w=12; pad=left('',5) /*width of columnar output; indentation*/
dash='─'; @b=
say pad c('N',5) c(@b) c(@b'%') c(@ub) c(@ub"%") c('samples') /*
dash=
do N=3 to R;
end
say pad c(N,5) c(b) pct(b) c(u) pct(u) c(#)
end /*N*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
c: return center( arg(1),
pct: return c( format(arg(1) / # * 100, , 2)'%' )
randN: parse arg z; return random(1, z)==z
unbiased: do until x\==randN(N); x=randN(N); end
'''output''' when using the default inputs:
<pre>
──N── ───biased─── ──biased%─── ──unbiased── ─unbiased%── ──samples───
Line 1,431 ⟶ 1,430:
6 178 17.80% 488 48.80% 1000
</pre>
'''output''' when using the input of: <tt> 10000 </tt>
<pre>
──N── ───biased─── ──biased%─── ──unbiased── ─unbiased%── ──samples───
Line 1,439 ⟶ 1,438:
6 1644 16.44% 4982 49.82% 10000
</pre>
'''output''' when using the input of: <tt> 100000 30 </tt>
<pre>
──N── ───biased─── ──biased%─── ──unbiased── ─unbiased%── ──samples───
|