edit: Or, if you do not trust isProbablePrime with enough confidence, use the BigInteger constructor BigInteger BigInteger(int bitLength, int certainty, Random rnd) , which allows you to set the certainty threshold:
certainty is a measure of the uncertainty that the caller wants to endure. The likelihood that the new BigInteger represents a prime number will exceed (1 - 1/2 certainty ). The runtime of this constructor is proportional to the value of this parameter.
The probabilistic tests used for cryptographic purposes guarantee the binding of the probability of false positives - it's not like there are any numbers found that will make their way through them, it's just a matter of how low the probability should be. If you don't trust the Java BigInteger class to use them (it would be nice if they documented which test was used), use the Rabin-Miller test.
source share