@GwtIncompatible // isPrime is GWT-incompatible public void testIsPrimeOnUniformRandom() { Random rand = new Random(1); for (int bits = 10; bits < 63; bits++) { for (int i = 0; i < 2000; i++) { // A random long between 0 and Long.MAX_VALUE, inclusive. long l = rand.nextLong() & ((1L << bits) - 1); assertEquals(BigInteger.valueOf(l).isProbablePrime(100), LongMath.isPrime(l)); } } }
boolean bigIntSays = bigInt.isProbablePrime(certainty); if(isPrime(i) != bigIntSays) { System.out.println("ERROR: isProbablePrime(" + certainty + ") returns "
@GwtIncompatible // isPrime is GWT-incompatible public void testIsPrimeSmall() { // Check the first 1000 integers for (int i = 2; i < 1000; i++) { assertEquals(BigInteger.valueOf(i).isProbablePrime(100), LongMath.isPrime(i)); } }
@GwtIncompatible // isPrime is GWT-incompatible public void testIsPrimeManyConstants() { // Test the thorough test inputs, which also includes special constants in the Miller-Rabin // tests. for (long l : POSITIVE_LONG_CANDIDATES) { assertEquals(BigInteger.valueOf(l).isProbablePrime(100), LongMath.isPrime(l)); } }
while(!BigInteger.valueOf(nLockTables).isProbablePrime(Integer.MAX_VALUE)) { nLockTables--;
/** * Returns a prime number, at least twice as large as needed. This should * minimize hash collisions. Since all the hash keys are known up front, * the capacity could be tweaked until there are no collisions, but this * technique is easier and deterministic. */ private static int hashCapacity(int min) { BigInteger capacity = BigInteger.valueOf(min * 2 + 1); while (!capacity.isProbablePrime(10)) { capacity = capacity.add(BigInteger.valueOf(2)); } return capacity.intValue(); }
public static ResultSet getPrimes(int beginRange, int endRange) throws SQLException { SimpleResultSet rs = new SimpleResultSet(); rs.addColumn("PRIME", Types.INTEGER, 10, 0); for (int i = beginRange; i <= endRange; i++) { if (new BigInteger(String.valueOf(i)).isProbablePrime(100)) { rs.addRow(i); } } return rs; }
@Property(trials = 10) public void factorsPassPrimalityTest( BigInteger n) { assumeThat(n, greaterThan(ZERO)); for (BigInteger each : PrimeFactors.of(n)) assertTrue(each.isProbablePrime(100)); }
/** * Prime checking routine * * @param N * @return return codes: 0 = Number is prime. 1 = Number is composite. */ private static int ProbabilisticPrimeTest(BigInteger N) { return N.isProbablePrime(32) ? 0 : 1; }
public static boolean isPrime(long n) { if (!BigInteger.valueOf(n).isProbablePrime(10)) return false; if (n > 2L && (n & 1L) == 0) return false; for (long i = 3L; i * i <= n; i += 2L) { if (n % i == 0) return false; } return true; }
public static boolean isPrime(long n) { if (!BigInteger.valueOf(n).isProbablePrime(10)) return false; if (n > 2L && (n & 1L) == 0) return false; for (long i = 3L; i * i <= n; i += 2L) { if (n % i == 0) return false; } return true; }
public static boolean isPrime(long n) { if (!BigInteger.valueOf(n).isProbablePrime(10)) return false; if (n > 2L && (n & 1L) == 0) return false; for (long i = 3L; i * i <= n; i += 2L) { if (n % i == 0) return false; } return true; }
@Override protected void adjustCapacity() { while(!(new BigInteger(String.valueOf(capacity)).isProbablePrime(20))) { capacity++; } }
for (int i=2; i <=100; i++) { BigInteger bi = new BigInteger(""+i); if (bi.isProbablePrime(9999)) { System.out.println("Prime: " + i); } }
public class Prime { public static void main(String[] args){ long start = System.nanoTime(); System.out.println("enter a number:"); Scanner scanner = new Scanner(System.in); BigInteger bigInt = scanner.nextBigInteger(); boolean prime = bigInt.isProbablePrime(10); System.out.println(prime); } }
public boolean apply(final IExpr obj) { try { final BigInteger value = ((IInteger) obj).getBigNumerator(); return value.isProbablePrime(32); } catch (final Exception e) { if (Config.DEBUG) { e.printStackTrace(); } } return false; }
protected RSAKeyParameters validateRSAPublicKey(RSAKeyParameters key) throws IOException { // TODO What is the minimum bit length required? // key.getModulus().bitLength(); if (!key.getExponent().isProbablePrime(2)) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } return key; } }
protected RSAKeyParameters validateRSAPublicKey(RSAKeyParameters key) throws IOException { // TODO What is the minimum bit length required? // key.getModulus().bitLength(); if (!key.getExponent().isProbablePrime(2)) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } return key; } }
protected RSAKeyParameters validateRSAPublicKey(RSAKeyParameters key) throws IOException { // TODO What is the minimum bit length required? // key.getModulus().bitLength(); if (!key.getExponent().isProbablePrime(2)) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } return key; } }
protected RSAKeyParameters validateRSAPublicKey(RSAKeyParameters key) throws IOException { // TODO What is the minimum bit length required? // key.getModulus().bitLength(); if (!key.getExponent().isProbablePrime(2)) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } return key; } }