• PHP Video Tutorials

PHP - gmp_random_bits()



Definition and Usage

The gmp_random_bits() function returns random number.

Description

The gmp_random_bits() function returns random GMP number based on the bits given.The number will be between 0 and (2 ** bits) - 1.

Syntax

gmp_random_bits ( int $bits ) : GMP

Parameters

Sr.No Parameter & Description
1

bits

The bits 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_bits() function returns random number that is a GMP rnumber.

PHP Version

This function will work from PHP Version greater than 5.6.3.

Example 1

Working of gmp_random_bits() −

<?php
   $rnum = gmp_random_bits(20);	
   echo "The random number generated is : ".$rnum;
?>

This will produce following result −

The random number generated is : 989073

Example 2

Working of gmp_random_bits −

<?php
   $rnum = gmp_random_bits(10);	
   echo "The random number generated is : ".$rnum;
?>

This will produce following result −

The random number generated is : 611
php_function_reference.htm
Advertisements