I have this method that will give a random prime for a given range (min inclusive an max not inclusive) all comments are welcome:public static int randomPrime(int min, int max) {    if (min < 0)        throw new IllegalArgumentException(min must be positive.);    if (min >= max)        throw new IllegalArgumentException(min must be smaller the max.);    if (!containsPrime(min,max))        throw new IllegalArgumentException(no Primes in this interval.);    if (rand == null) {        rand = new Random();    }    int out = rand.nextInt(max - min) + min;    while (!isPrime(out)) {        out = rand.nextInt(max - min) + min;    }    return out;}    private static boolean containsPrime(int min, int max) {    if (isPrime(min)||isPrime(max-1)){        return true;    }    if(min%2==0){        min +=1;    }    while (min<max){        if (isPrime(min)){            return true;        }        min +=2;    }    return false;}
Random Prime generator
java;primes
First of all, use some white space. The scrunched expressions are harder to read. At a minimum, I recommend spaces around every operator.In containsPrime, if the variable min is odd, then it gets checked twice. You can replace the second if block with this:if (min % 2 == 0) min += 1;else min += 2;