gpt4 book ai didi

java - 为什么 Java BigInteger 说 'probably prime' 而不是 'certainly prime' ?

转载 作者:行者123 更新时间:2023-12-01 07:00:53 25 4
gpt4 key购买 nike

BigInteger的JavaDoc让我感觉很不安全,例如下面的构造函数说:

BigInteger(int bitLength, int certainty, Random rnd)

Constructs a randomly generated positive BigInteger that is probably prime, with the specified bitLength.

为什么只是可能?为什么不肯定呢?我仍然可以相信结果是素数吗?

最佳答案

来自docs对于 BigInteger(int bitLength, int certainty, Random rnd) :

certainty: a measure of the uncertainty that the caller is willing to tolerate. The probability that the new BigInteger represents a prime number will exceed (1 - ½certainty). The execution time of this constructor is proportional to the value of this parameter.

因此,构造函数可以让您指定它将是素数的确定性,这就是文档说“可能”的原因

关于java - 为什么 Java BigInteger 说 'probably prime' 而不是 'certainly prime' ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53243130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com