   while go 
     await srf.recharge defer()
     p = new BigInteger nbits, srf
-    p = prime_search p, 4 * sieve.length * nbits, sieve, iters
+    p = prime_search p, 2 * sieve.length * nbits, sieve, iters
     go = (p.compareTo(BigInteger.ZERO) is 0)
     console.log "iter #{i++} -> #{go}"
   cb p

exports.miller_rabin = miller_rabin
exports.random_prime = random_prime

await random_prime 3072, 32, defer p
console.log p.toString()
process.exit -1


# @param {BigInteger} n
# @return {Boolean} true if the check succeeds and false otherwise.
#
fta = new Avg()
fermat2_test = (n) ->
  fta.start()
  t = nbv(1)
  bl = n.bitLength()
  bl--
  for i in [bl..0]
    t = t.modPowInt(2,n)
    #t = t.square()

    # .t in jsbn is equivalent to _mp_size in GNU bigint.  _mp_size
    # is the "number of limbs" in the bigint
    #if t.t > n.t
    #  t = t.mod(n)
    if n.testBit(i)
      t = t.shiftLeft(1)
  if t.compareTo(n) > 0
    t = t.mod(n)
  ret = (t.compareTo(nbv(2)) is 0)
  fta.stop()
  ret

#--------------
