RandomUtils { public static int nextTwinPrime(int n) { if (n > MAX_INT_SMALLER_TWIN_PRIME) { throw new IllegalArgumentException(); } if (n <= 3) { return 5; } int next = Primes.nextPrime(n); while (!Primes.isPrime(next + 2)) { next = Primes.nextPrime(next + 4); } return next + 2; } private  RandomUtils(); static void useTestSeed(); static RandomWrapper getRandom(); static Random getRandom(long seed); static int hashDouble(double value); static int hashFloat(float value); static int nextTwinPrime(int n); static final int MAX_INT_SMALLER_TWIN_PRIME; }
@Test public void testNextTwinPrime() { assertEquals(5, RandomUtils.nextTwinPrime(-1)); assertEquals(5, RandomUtils.nextTwinPrime(1)); assertEquals(5, RandomUtils.nextTwinPrime(2)); assertEquals(5, RandomUtils.nextTwinPrime(3)); assertEquals(7, RandomUtils.nextTwinPrime(4)); assertEquals(7, RandomUtils.nextTwinPrime(5)); assertEquals(13, RandomUtils.nextTwinPrime(6)); assertEquals(RandomUtils.MAX_INT_SMALLER_TWIN_PRIME + 2, RandomUtils.nextTwinPrime(RandomUtils.MAX_INT_SMALLER_TWIN_PRIME)); try { RandomUtils.nextTwinPrime(RandomUtils.MAX_INT_SMALLER_TWIN_PRIME + 1); fail(); } catch (IllegalArgumentException iae) { } }