Anonymous user
Unbias a random generator: Difference between revisions
→{{header|REXX}}: added support for the RANGE of the tallies, added indentation, changed some column headers to include %.
m (→{{header|REXX}}: used literal variables instead of literals, added/changed whitespace and comments.) |
(→{{header|REXX}}: added support for the RANGE of the tallies, added indentation, changed some column headers to include %.) |
||
Line 1,329:
=={{header|REXX}}==
<lang rexx>/*REXX program generates unbiased random numbers and displays the results. */
parse arg # R seed .
if #=='' | #==',' then #=1000 /*# the number of SAMPLES to be used.*/
if R=='' | R==',' then R=6 /*R the high number for the range. */
if seed\=='' then call random ,,seed /*Not specified? Use for RANDOM seed. */
w=
dash='─'; @b='biased'; @ub='un'@b /*literals for the SAY column headers. */
say
dash=
do N=3 to
end /*j*/
say
end /*N*/
exit /*stick a fork in it, we're all done. */
/*───────────────────────────────────one─liner subroutines────────────────────*/
randN: parse arg z; return random(1,z)==z
unbiased: do until x\==randN(N); x=randN(N); end; return x</lang>
'''output''' when using the
<pre>
──N── ───biased─── ──biased%─── ──unbiased── ─unbiased%── ──samples───
</pre>
'''output''' when using the
<pre>
──N── ───biased─── ──biased%─── ──unbiased── ─unbiased%── ──samples───
</pre>
'''output''' when using the input of: <tt>
<pre>
──N── ───biased─── ──biased%─── ──unbiased── ─unbiased%── ──samples───
7 14294 14.29% 50008 50.01% 100000
8 12402 12.40% 50479 50.48% 100000
9 11138 11.14% 50099 50.10% 100000
10 9973 9.97% 49988 49.99% 100000
11 9062 9.06% 50009 50.01% 100000
12 8270 8.27% 49929 49.93% 100000
13 7704 7.70% 49876 49.88% 100000
14 7223 7.22% 50414 50.41% 100000
15 6725 6.73% 50043 50.04% 100000
16 6348 6.35% 50252 50.25% 100000
17 5900 5.90% 49977 49.98% 100000
18 5583 5.58% 49991 49.99% 100000
19 5139 5.14% 49958 49.96% 100000
20 4913 4.91% 50198 50.20% 100000
21 4714 4.71% 49892 49.89% 100000
22 4517 4.52% 49760 49.76% 100000
23 4226 4.23% 50021 50.02% 100000
24 4174 4.17% 50141 50.14% 100000
25 4005 4.01% 49816 49.82% 100000
26 3890 3.89% 49819 49.82% 100000
27 3705 3.71% 50036 50.04% 100000
28 3567 3.57% 49665 49.67% 100000
29 3481 3.48% 50094 50.09% 100000
30 3355 3.36% 49831 49.83% 100000
</pre>
|