Friday, October 24, 2025
HomeLanguagesPHP | gmp_prob_prime() Function

PHP | gmp_prob_prime() Function

The gmp_prob_prime() is a built-in function in PHP which is used to check how much is the possibility of given GMP number(GNU Multiple Precision : For large numbers) to be prime or not.
This function uses Miller-Rabin primality test to check if the given GMP number is prime or not.

Syntax:

gmp_prob_prime($num)

Parameters: The function accepts a GMP number $num as mandatory parameter as shown in the above syntax. This parameter can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass numeric string such that it is possible to convert this string in number.

Return Value: This function returns value in the range 0-2, 0 if the number is definitely not prime, 1 if the number may be prime else 2 if the number is surely prime.

Examples:

Input : gmp_prob_prime("8")
Output : 0

Input : gmp_prob_prime("11111111111111")
Output : 1

Input: gmp_prob_prime("127")
Output:  2

Below programs illustrate the gmp_prob_prime() function in PHP:

Program 1: Program to find the prime probability of GMP number when numeric strings as GMP numbers are passed as arguments.




<?php
// PHP program to find the prime probability of
// GMP numbers passed as arguments 
  
// strings as GMP numbers
$num = "17";
  
// calculate the possibility
// of GMP number to be prime
$prob = gmp_prob_prime($num);
   
echo $prob;
?>


Output:

2

Program 2: Program to find the prime probability of GMP number when GMP numbers are passed as arguments.




<?php
// PHP program to find the prime probability of
// GMP numbers passed as arguments 
  
// creating GMP numbers using gmp_init()
$num = gmp_init(8);
  
// calculate the possibility of
// GMP number to be prime
$prob = gmp_prob_prime($num);
  
echo $prob;
?>


Output:

0

Program 3: Program to find the prime probability of GMP number when GMP numbers are passed as arguments.




<?php
// PHP program to find the prime probability of
// GMP numbers passed as arguments 
  
// creating GMP numbers using gmp_init()
$num = gmp_init(1111111111111111111);
  
// calculate the possibility of
// GMP number to be prime
$prob = gmp_prob_prime($num);
  
echo $prob;
?>


Output:

1

Reference:
php.net/manual/en/function.gmp-prob-prime.php

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS