Jump to content

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}}==
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.