Java BigInteger类| 带有示例的probablePrime()方法

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值