简体   繁体   中英

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(int bitLength, int certainty, Random rnd)

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

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) :

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.

So the constructor lets you specify the certainty that it will be prime, which is why the docs say "probably"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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