Unbias a random generator: Difference between revisions

Content added Content deleted
(→‎Tcl: Added implementation)
(J)
Line 7: 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.
* 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).
* 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}}==
=={{header|Python}}==