import java.math.*;
import java.util.*;
class CreatePrime
{
public static void main( String args[]) {
int bitLength = 128;
int certainty = 10;
BigInteger prime = new BigInteger( bitLength,
certainty, new Random());
System.out.println( prime.toString());
}
}
Test a number is it a prime
java.math.BigInteger
public boolean isProbablePrime(int certainty)
Returns true if this BigInteger is probably prime, false if it's definitely
composite. The certainty parameter is a measure of the uncertainty that
the caller is willing to tolerate: the method returns true if the probability
that this number is is prime exceeds 1 - 1/2**certainty. The execution
time is proportional to the value of the certainty parameter.