1

BigInteger in Java has constructor that generates prime numbers, I cant find any mention of what algorithm is used in this. Is there a name of algorithm or maybe a book where this algorithm described?

Akiles
  • 11
  • 1

2 Answers2

1

It is recommended that the probablePrime method be used in preference to this constructor unless there is a compelling need to specify a certainty. - from Java 7 BigInteger API docs

Having said that. BigInteger's probable prime methods use both the Miller-Rabin and Lucas-Lehmer algorithms to test primality.

See passesMillerRabin(rounds, random) && passesLucasLehmer(); in BigInteger internal method primeToCertainty from java 7.

Further reading on:

  1. Miller-Rabin primality test (Java)
  2. Lucas-Lehmer test
Laurentiu L.
  • 6,566
  • 1
  • 34
  • 60
0

The algorithm used is an implementation detail that may vary from jdk to jdk, even between versions. The contract is only that it gives you a prime number, not that it follows any given algorithm to do so.

corsiKa
  • 81,495
  • 25
  • 153
  • 204