A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/java/java-math-biginteger-probableprime-method-in-java/ below:

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

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.

Return Value:

This method returns a BigInteger of

bitLength

bits that is probably prime.

Exception:

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)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4