BigInteger类的probablePrime()方法 (BigInteger Class probablePrime() method)
probablePrime() method is available in java.math package.
probablePrime()方法在java.math包中可用。
probablePrime() method is used to get the BigInteger that holds the positive probable prime value with the given length.
probablePrime()方法用于获取BigInteger,该值具有给定长度的正可能质数。
probablePrime() method is a static method, it is accessible with the class name and if we try to access the method with the class object then we will not get any error.
probablePrime()方法是一个静态方法,可以使用类名进行访问,如果尝试使用类对象访问该方法,则不会出现任何错误。
probablePrime() method may throw an exception at the time of getting probable prime.
probablePrime()方法在获取可能的素数时可能会引发异常。
ArithmeticException: This exception may throw when the given first parameter value is not in a range.
ArithmeticException :如果给定的第一个参数值不在范围内,则可能引发此异常。
Syntax:
句法:
public BigInteger probablePrime(int len, Random ran);
Parameter(s):
参数:
int len – represents the length of bits to denote this BigInteger value.
int len –表示表示此BigInteger值的位的长度。
Random ran – represents the list of random bits to choose for checking prime value.
随机运行 –表示要检查素数的随机位列表。
Return value:
返回值:
The return type of this method is BigInteger, it returns BigInteger that holds the prime value with the defined length of bits.
该方法的返回类型为BigInteger ,它返回BigInteger,其中包含具有定义的位长的质数。
Example:
例:
// Java program to demonstrate the example
// of BigInteger probablePrime(int len, Random ran)
// method of BigInteger
import java.math.*;
import java.util.*;
public class ProbablePrimeOfBI {
public static void main(String args[]) {
// Initializes a variables bit_len
int bit_len = 4;
// Initializes a Random object
Random ran = new Random();
// Here, this method probablePrime(int,Random)
// is used to return the random prime
// number with the given bit length i.e. it
// returns randomly 11 so the bit length of
// 11 is 4 like 1011
BigInteger prime = BigInteger.probablePrime(bit_len, ran);
System.out.println("BigInteger.probablePrime(bit_len,ran): " + prime);
}
}
Output
输出量
BigInteger.probablePrime(bit_len,ran): 11
翻译自: https://www.includehelp.com/java/biginteger-probableprime-method-with-example.aspx