Unbias a random generator: Difference between revisions

m
(Added Kotlin)
Line 1,081:
template newSeqWith(len: int, init: expr): expr =
var result {.gensym.} = newSeq[type(init)](len)
for i in 0 .. <len:
result[i] = init
result
 
proc randN(n): (proc: range[0..1]) =
result = proc(): range[0..1] = ord(random(n) == 0)
if random(n) == 0: 1 else: 0
 
proc unbiased(biased): range[0..1] =
var (this, that)result = (biased(), biased())
whilevar thisthat == that:biased()
while result == that:
thisresult = biased()
that = biased()
return this
 
for n in 3..6:
Anonymous user