Unbias a random generator: Difference between revisions

Content added Content deleted
(→‎{{header|Elixir}}: removed unnecessary limitation.)
m (→‎{{header|REXX}}: removed STYLE/OVERFLOW from the PRE html tags.)
Line 1,349: Line 1,349:
randN: parse arg z; return random(1, z)==z
randN: parse arg z; return random(1, z)==z
unbiased: do until x\==randN(N); x=randN(N); end; return x</lang>
unbiased: do until x\==randN(N); x=randN(N); end; return x</lang>
'''output''' when using the input of: <tt> 100 </tt>
'''output''' when using the input of: &nbsp; <tt> 100 </tt>
<pre>
<pre style="overflow:scroll">
─N─ ────biased──── ────biased──── ───unbiased─── ───unbiased─── ───samples────
─N─ ────biased──── ────biased──── ───unbiased─── ───unbiased─── ───samples────
3 31 31.00% 50 50.00% 100
3 31 31.00% 50 50.00% 100
Line 1,357: Line 1,357:
6 16 16.00% 51 51.00% 100
6 16 16.00% 51 51.00% 100
</pre>
</pre>
'''output''' when using the default input of: <tt> 1000 </tt>
'''output''' when using the default input of: &nbsp; <tt> 1000 </tt>
<pre>
<pre style="overflow:scroll">
─N─ ────biased──── ────biased──── ───unbiased─── ───unbiased─── ───samples────
─N─ ────biased──── ────biased──── ───unbiased─── ───unbiased─── ───samples────
3 317 31.70% 484 48.40% 1000
3 317 31.70% 484 48.40% 1000
Line 1,365: Line 1,365:
6 164 16.40% 493 49.30% 1000
6 164 16.40% 493 49.30% 1000
</pre>
</pre>
'''output''' when using the input of: <tt> 10000 </tt>
'''output''' when using the input of: &nbsp; <tt> 10000 </tt>
<pre>
<pre style="overflow:scroll">
─N─ ────biased──── ────biased──── ───unbiased─── ───unbiased─── ───samples────
─N─ ────biased──── ────biased──── ───unbiased─── ───unbiased─── ───samples────
3 3366 33.66% 5023 50.23% 10000
3 3366 33.66% 5023 50.23% 10000