Java.math.BigInteger.probablePrime() method in Java Last Updated : 04 Dec, 2018 Comments Improve Suggest changes Like Article Like Report Prerequisite : BigInteger Basics The probablePrime() method will return a Biginteger of bitLength bits which is prime. bitLength is provided as parameter to method probablePrime() and method will return a prime BigInteger of bitLength bits. The probability that a BigInteger returned by this method is composite and does not exceed 2^-100. Syntax: public static BigInteger probablePrime(int bitLength, Random rnd) Parameters: This method accepts two parameters as shown in the above syntax and described below. bitLength - bitLength of the returned BigInteger. rnd - source of random bits used to select candidates to be tested for primality. Return Value: This method returns a BigInteger of bitLength bits that is probably prime. Exception: ArithmeticException - if bitLength < 2. Below program illustrate the probablePrime() method: Java import java.math.*; import java.util.Random; import java.util.Scanner; public class GFG { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // create a BigInteger object BigInteger biginteger; // create a integer value for bitLength int length = 4; // create a random object Random random = new Random(); // call probablePrime method to find next probable prime // whose bit length is equal to bitLength provided as parameter. biginteger = BigInteger.probablePrime(length, random); String result = "ProbablePrime whose bit length is " + length + " = " + biginteger; // print result value System.out.println(result); } } Output: ProbablePrime whose bit length is 4 = 13 Reference:https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#probablePrime(int, %20java.util.Random) Comment More infoAdvertise with us Next Article Java.math.BigInteger.probablePrime() method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions java-math Java-BigInteger Java-math-package +2 More Practice Tags : JavaJava-BigInteger Similar Reads Java.math.BigInteger.modInverse() method in Java Prerequisite : BigInteger Basics The modInverse() method returns modular multiplicative inverse of this, mod m. This method throws an ArithmeticException if m <= 0 or this has no multiplicative inverse mod m (i.e., gcd(this, m) != 1). Syntax: public BigInteger modInverse(BigInteger m) Parameters: 2 min read BigInteger nextProbablePrime() Method in Java with Examples The java.math.BigInteger.nextProbablePrime() is used to find the first integer greater than this BigInteger that is probably prime. If this method returns 'p' then there is no prime number 'q' between this Biginteger and 'p' (this < q < p ) i.e. it never skips any prime number greater than Big 3 min read BigInteger or() method in Java Prerequisite: BigInteger Basics The java.math.BigInteger.or(BigInteger val) method is used to perform bitwise OR of two BigIntegers. One of the BigInteger is passed in parameter and the other on which the function is called. This method returns a negative number if either of the BigIntegers used wit 2 min read BigInteger pow() Method in Java The java.math.BigInteger.pow(int exponent) method is used to calculate a BigInteger raise to the power of some other number passed as exponent whose value is equal to (this)exponent. This method performs operation upon the current BigInteger by which this method is called and exponent passed as para 2 min read BigInteger remainder() Method in Java The java.math.BigInteger.remainder(BigInteger big) method returns a BigInteger whose value is equal to (this BigInteger % big(BigInteger passed as parameter)).The remainder operation finds the remainder after division of this BigInteger by another BigInteger passed as parameter. Syntax: public BigIn 3 min read Like