static BigInteger findAPrime(int min, int max) {
		int nbits = log2(max);
		int tries = 0;
		BigInteger p;
		do {
			p = new BigInteger(nbits, rnd);
			if (p.mod(BigInteger.valueOf(2)).equals(BigInteger.ZERO)) continue;
			if (p.mod(BigInteger.valueOf(3)).equals(BigInteger.ZERO)) continue;
			if (p.mod(BigInteger.valueOf(5)).equals(BigInteger.ZERO)) continue;
			if (p.mod(BigInteger.valueOf(7)).equals(BigInteger.ZERO)) continue;
			tries++;
			if (tries > (10 * log2(max) + 3)) return BigInteger.ZERO;         //fail to find the prime

		} while (!millerRabin(p) || 
				p.compareTo(BigInteger.valueOf(max)) > 0 ||
				p.compareTo(BigInteger.valueOf(min)) < 0);
		return p;
	}