解決できないような問題があります。私の数が相対性理論の素数であるかどうかを判断するために、ランダムに数を生成しています。
浮動小数点例外を発生させる関数は次のとおりです。
bool modularExponentiationTest(unsigned long long exponent, unsigned long long modulus)
{
short index = 0;
unsigned long long base;
unsigned long long result;
do
{
result = 1;
base = rand() % exponent; // <--CAUSED BY THIS
while (exponent > 0)
{
if (exponent & 1)
result = (result * base) % modulus;
exponent >>= 1;
base = (base * base) % modulus;
}
if (result != 1)
return false;
}while(++index < 10);
return true;
}
次のようにして、別の関数でランダムシードを実行しました。
srand(time(NULL));
ご助力ありがとうございます!