简体   繁体   English

Java BigInteger为什么说“可能是素数”而不是“肯定是素数”?

[英]Why does Java BigInteger say 'probably prime' and not 'certainly prime'?

The JavaDoc of BigInteger makes me feel very insecure, for example the following constructor says: BigInteger的JavaDoc使我感到非常不安全,例如以下构造函数说:

BigInteger(int bitLength, int certainty, Random rnd)

Constructs a randomly generated positive BigInteger that is probably prime, with the specified bitLength. 使用指定的bitLength构造一个随机生成的可能为素数的正BigInteger。

Why only probably? 为什么只有可能? Why not certainly? 为什么不肯定呢? Can I still trust that the result would be a prime number? 我仍然可以相信结果将是质数吗?

From the docs for BigInteger(int bitLength, int certainty, Random rnd) : BigInteger(int bitLength, int certainty, Random rnd)文档中:

certainty : a measure of the uncertainty that the caller is willing to tolerate. certainty :确定呼叫者愿意容忍的不确定性。 The probability that the new BigInteger represents a prime number will exceed (1 - ½ certainty ). 新的BigInteger表示质数的概率将超过(1-½ 确定性 )。 The execution time of this constructor is proportional to the value of this parameter. 该构造函数的执行时间与该参数的值成比例。

So the constructor lets you specify the certainty that it will be prime, which is why the docs say "probably" 因此,构造函数可让您指定将其定为素数的确定性,这就是为什么文档说“可能”的原因

因为概率算法的运行速度比验证数字绝对是质数快得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM