gmp_prob_prime
is a function in PHP that checks whether or not the argument passed is probably prime.
This function uses Miller-Rabin’s probabilistic test to check the prime nature of numbers.
gmp_prob_prime(GMP|int|string $num, int $repetitions = 10): int
The function takes in two parameters:
num
- the number that is going to be checked for prime number.
repetitions
- this is an optional parameter. The value of repetition varies from 5 to 10. The default value is 10.
num
andrepetitions
can be a numeric string, GMP object, or of theint
type.
The function returns 0
if the function is not prime.
The function returns 1
if the function is prime.
The function returns 2
if the function is prime.
<?php// number is not primeecho gmp_prob_prime("2") . "\n";// number is probably primeecho gmp_prob_prime("111111111") . "\n";// number is surely primeecho gmp_prob_prime("13") . "\n";?>
0
1
2