All,
I have implemented a code that generates 2 random prime numbers and the multiplication of these 2 numbers should pass the Miller Rabin primality test. However, my code keeps looping all the time trying to find a number that passes Miller rabin test and ends up with a Stackoverflow exception. Here is the code:
private void populateRandomPrimes()
{
onePrimeValue = RandomPrime.getValue();
do
{
secondPrimeValue= RandomPrime.getValue();
}while(onePrimeValue == secondPrimeValue);
BigInteger calcNum = new BigInteger(Integer.toString(onePrimeValue*secondPrimeValue));
try
{
**if (calcNum.isProbablePrime(20))**
populateMultiplicativeForPlayer();
else
populateRandomPrimes();
}
catch (Exception io)
{
io.printStackTrace();
}
}
In the code above:
1 > RandomPrime class returns a random prime number
2 > Both onePrimeValue and secondPrimeValue should be different
3 > Since the code line : if (calcNum.isProbablePrime(20)) never returns a true, I end up calling the same till I get Stackoverflow exception
Can anyone suggest me how to get around with this issue?
Please see my comment below your question…