Algorithm used by BigInteger prime generator?

Alexandre Oliva oliva at
Thu Apr 22 02:36:42 PDT 1999

On Apr 20, 1999, Paul Fisher <rao at> wrote:

> Alexandre Oliva <oliva at> writes:
>> Does anybody know what algorithm the constructor
>> java.math.BigInteger.BigInteger(int bitLength, int certainty, Random
>> rnd) is supposed to use?

> Sun's java.math implementation uses Colin Plumb's <colin at>
> BigNum library <URL:>.
> You'll find the prime number generation routines there.

The problem is that there's no specification about what to do after
generating a random number, nor does it talk about ``adjusting'' a
randomly-generated number so that it passes a primality test.  For
example, Plumb's primeGen doesn't provide a mechanism to specify a

Furthermore, Plumb's implementation accepts a rand function as an
argument, that takes only an unsigned integer as argument, to
randomize the increments to the base random number.  I don't see how
Sun might have written a wrapper function that would call back the
Random generator passed as argument, since it wouldn't be able to
figure out which Random object to invoke...  But then, this is not an
issue, since we wouldn't be using Plumb's implementation anyway.

I'm going to install a very dumb implementation, and improve it when I 
get input from Sun about the actual algorithm that should be used.

Alexandre Oliva IC-Unicamp, Brasil
{oliva,Alexandre.Oliva}  aoliva@{,}
*** E-mail about software projects will be forwarded to mailing lists

More information about the kaffe mailing list