What is the gmp_prob_prime function in PHP?
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.
Syntax
gmp_prob_prime(GMP|int|string $num, int $repetitions = 10): int
Parameters
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.
numandrepetitionscan be a numeric string, GMP object, or of theinttype.
Return value
-
The function returns
0if the function is not prime. -
The function returns
1if the function is prime. -
The function returns
2if the function is prime.
Code
<?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";?>
Output
0
1
2