VOOZH about

URL: https://www.geeksforgeeks.org/java/java-math-biginteger-probableprime-method-in-java/

⇱ Java.math.BigInteger.probablePrime() method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java.math.BigInteger.probablePrime() method in Java

Last Updated : 11 Jul, 2025
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: 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