RandomUtils { public static int nextPrime(int n) { if (n <= 2) { return 2; } n |= 0x1; while (isNotPrime(n)) { n += 2; } return n; } private  RandomUtils(); static void useTestSeed(); static Random getRandom(); static Random getRandom(long seed); static byte[] longSeedtoBytes(long seed); static long seedBytesToLong(byte[] seed); static int hashDouble(double value); static int hashFloat(float value); static int nextTwinPrime(int n); static int nextPrime(int n); static boolean isNotPrime(int n); static final int MAX_INT_SMALLER_TWIN_PRIME; }
@Test public void testNextPrime() { assertEquals(2, RandomUtils.nextPrime(-1)); assertEquals(2, RandomUtils.nextPrime(1)); assertEquals(2, RandomUtils.nextPrime(2)); assertEquals(3, RandomUtils.nextPrime(3)); assertEquals(5, RandomUtils.nextPrime(4)); assertEquals(5, RandomUtils.nextPrime(5)); assertEquals(7, RandomUtils.nextPrime(6)); assertEquals(Integer.MAX_VALUE, RandomUtils.nextPrime(Integer.MAX_VALUE - 1)); }