 
 #-----------------------
 
-
 #
 # Find a random prime that is nbits long, with certainty
 # 1 - 2^{-iter}

    await srf.recharge defer()
    p = new BigInteger nbits, srf
    p = p.setBit(0).setBit(nbits-1)
    progress_hook? { what : "guess", p }
    p = prime_search p, nbits/4, sieve, progress_hook, iters
    go = (p.compareTo(BigInteger.ZERO) is 0)
  progress_hook? { what : "found", p }
  cb p


# Use the sieve for primality testing, which in the case of regular odd
# primes is [1,2], and for strong primes is more interesting...
#
prime_search = ({start, range, sieve, progress_hook, iters}) ->
  iters or= 20
  pf = new PrimeFinder start, sieve
  pf.setmax range
  pvec = (pp while ((pp = pf.next_weak()).compareTo(BigInteger.ZERO) > 0))
