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

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

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

BigInteger(int bitLength, int certainty, Random rnd)

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

为什么只有大概?为什么不肯定?我还能相信结果会是质数吗?

来自 docsBigInteger(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.

所以构造函数让你确定它将是质数,这就是为什么文档说 "probably"

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