/** * Test probable primes in the sieve and return successful candidates. */ BigInteger retrieve(BigInteger initValue, int certainty, java.util.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 >>>= 1; offset+=2; } } return null; } }
/** * Test probable primes in the sieve and return successful candidates. */ BigInteger retrieve(BigInteger initValue, int certainty, java.util.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 >>>= 1; offset+=2; } } return null; } }
if (p.primeToCertainty(certainty, rnd)) return p;
if (p.primeToCertainty(certainty, rnd)) return p;
/** * Returns {@code true} if this BigInteger is probably prime, * {@code false} if it's definitely composite. If * {@code certainty} is ≤ 0, {@code true} is * returned. * * @param certainty a measure of the uncertainty that the caller is * willing to tolerate: if the call returns {@code true} * the probability that this BigInteger is prime exceeds * (1 - 1/2<sup>{@code certainty}</sup>). The execution time of * this method is proportional to the value of this parameter. * @return {@code true} if this BigInteger is probably prime, * {@code false} if it's definitely composite. */ public boolean isProbablePrime(int certainty) { if (certainty <= 0) return true; BigInteger w = this.abs(); if (w.equals(TWO)) return true; if (!w.testBit(0) || w.equals(ONE)) return false; return w.primeToCertainty(certainty, null); }
/** * Returns {@code true} if this BigInteger is probably prime, * {@code false} if it's definitely composite. If * {@code certainty} is ≤ 0, {@code true} is * returned. * * @param certainty a measure of the uncertainty that the caller is * willing to tolerate: if the call returns {@code true} * the probability that this BigInteger is prime exceeds * (1 - 1/2<sup>{@code certainty}</sup>). The execution time of * this method is proportional to the value of this parameter. * @return {@code true} if this BigInteger is probably prime, * {@code false} if it's definitely composite. */ public boolean isProbablePrime(int certainty) { if (certainty <= 0) return true; BigInteger w = this.abs(); if (w.equals(TWO)) return true; if (!w.testBit(0) || w.equals(ONE)) return false; return w.primeToCertainty(certainty, null); }
if (result.primeToCertainty(DEFAULT_PRIME_CERTAINTY, null)) return result;
if (result.primeToCertainty(DEFAULT_PRIME_CERTAINTY, null)) return result;