Unbias a random generator: Difference between revisions
J
(→Tcl: Added implementation) |
(J) |
||
Line 7:
* Create a function '''unbiased''' that uses only randN as its source of randomness to become an unbiased generator of random ones and zeroes.
* For N over its range, generate and show counts of the outputs of randN and unbiased(randN).
=={{header|J}}==
<lang j>biased=: 0 = ?
unbiased=: i.@# { 2 | 0 3 -.~ _2 #.\ biased@#~@#~&2 ::$:</lang>
Example use:
<lang j> biased 10#6
1 0 0 0 1 0 0 0 0 0
unbiased 10#6
1 0 0 1 0 0 1 0 1 1</lang>
=={{header|Python}}==
|