Friday, October 10, 2025
HomeLanguagesPHP | gmp_random_seed() Function

PHP | gmp_random_seed() Function

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

Syntax:

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.

Note:

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
  
// PHP code implementing the gmp_random_seed function
  
// setting the seed
gmp_random_seed(100);
  
var_dump(gmp_strval(gmp_random(1)));
  
?>


Output:

string(19) "7842303329126688544"

Program 2:




<?php
//php code implementing the gmp_random_seed() function
  
// set the seed to something else
gmp_random_seed(gmp_init(-100));
  
var_dump(gmp_strval(gmp_random_bits(10)));
  
?>


Output:

string(3) "800"

Program 3:




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


Output:

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

Related Articles:

Reference: http://php.net/manual/en/function.gmp-random-seed.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6718 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7101 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS