/// <summary> /// Test probable primes in the sieve and return successful candidates. /// </summary> internal virtual BigInteger Retrieve(BigInteger initValue, int certainty, Random random) { // Examine the sieve one long at a time to find possible primes int offset = 1; for (int i = 0; i < Bits.Length; i++) { long nextLong = ~Bits[i]; for (int j = 0; j < 64; j++) { if ((nextLong & 1) == 1) { BigInteger candidate = initValue.Add(BigInteger.ValueOf(offset)); if (candidate.PrimeToCertainty(certainty, random)) { return(candidate); } } nextLong = (long)((ulong)nextLong >> 1); offset += 2; } } return(null); }