• PHP Video Tutorials

PHP - gmp_random() Function



Definition and Usage

The gmp_random() function returns random number.

Description

The gmp_random() function returns random GMP number based on the limit given.The number will be between 0 and (2 ** n) - 1, where n is the number of bits per limb multiplied by limiter. If the limiter given is negative,the random number will be negative.The limb is internally used in GMP class, and it can be either 32 or 64 and can vary from system to system.

Syntax

gmp_random ([ int $limiter = 20 ] ) : GMP

Parameters

Sr.No Parameter & Description
1

limiter

The limiter to be used to generate random number.It can a GMP resource number , a gmp object or a numeric string.

Return Values

PHP gmp_random() function returns random number that is a GMP rnumber.

PHP Version

This function will work from PHP Version greater than 5.0.0.

Example 1

Working of gmp_sub −

<?php
   $rnum = gmp_random(2);	
   echo "The result is : ".$rnum;
?>

This will produce following result −

The result is : 216080900246540042130805817492934209193

Example 2

Working of gmp_sub −

<?php
   $rnum = gmp_random(1);	
   echo "The result is : ".$rnum;
?>

This will produce following result −

The result is : 1072402112374286374
php_function_reference.htm
Advertisements