這裏是我使用gmp_prob_prime的一段代碼。儘管我目前只在10^6範圍內測試數字,但這個函數非常經常地「失敗」我的QuickTest,並且最終需要手動檢查$ NumberToTest的素數。PHP中的函數gmp_prob_prime有點缺乏光澤嗎?
gmp_prob_prime不是很強大嗎?我沒有料到它會在10^9甚至10^12的範圍內提示「可能的素數」。
這裏是我的代碼的功能的片段,是被稱爲:
function IsPrime($DocRoot, $NumberToTest, $PowOf2)
{
// First a quick test...
// 0 = composite
// 1 = probable prime
// 2 = definite prime
$Reps = 15;
$QuickTest = gmp_prob_prime($NumberToTest,$Reps);
if($QuickTest == 0)
{
return 0;
}
if ($QuickTest == 2)
{
return 1;
}
// If we get to here then gmp_prob_prime isn't sure whether the $NumberToTest is prime or not.
print "Consider increasing the Reps for gmp_prob_prime.\n";
// Find the sqrt of $NumberToTest;
...代碼繼續...