Java tutorial
import java.math.BigInteger; import java.security.SecureRandom; public class Main { public static void main(String[] args) throws Exception { int bitLength = 512; // 512 bits SecureRandom rnd = new SecureRandom(); int certainty = 90; // 1 - 1/2(90) certainty BigInteger mod = new BigInteger(bitLength, certainty, rnd); System.out.println(mod); } }