Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

PHP | gmp_random_seed() Function

  • Last Updated : 19 Jun, 2018

The gmp_random_seed() is an inbuilt function in PHP which sets the RNG seed( Random Number Generation).


void gmp_random_seed ( mixed $seed )

Parameters: The gmp_random_seed() function accepts a single parameter as mentioned above and explained below:

  • $seed: It is the only parameter required by the gmp_random_seed() function which is to be set for gmp_random(), gmp_random_range() and gmp_random_bits() functions. This parameter can be a GMP resource in PHP 5.5 or earlier, a GMP object in PHP version 5.6 and later, or also allowed to pass a numeric string provided that it is possible to convert that string to a number.

Return Value: The gmp_random_seed() function returns NULL on success and returns FALSE on failure.


Warning: The function generates an E-Warning and returns False if the seed is not valid.

Examples: Below programs illustrate the gmp_random_seed() function in PHP:

Program 1:

// PHP code implementing the gmp_random_seed function
// setting the seed


string(19) "7842303329126688544"

Program 2:

//php code implementing the gmp_random_seed() function
// set the seed to something else


string(3) "800"

Program 3:

//PHP code implementing gmp_random_seed() function 
// set the seed to something invalid
var_dump(gmp_random_seed('not a number'));


gmp_random_seed(): Unable to convert variable to GMP - string is not an integer -- at line 5

Related Articles:


My Personal Notes arrow_drop_up
Recommended Articles
Page :