srand() function in PHP

PHPProgrammingServer Side Programming

The mt_srand() function seeds the random number generator.

Note − Random number generator is seeded automatically after the release of PHP 4.2.0. This function is not needed now.

Syntax

srand(seed)

Parameters

  • seed − The seed value

Return

The srand() function Returns nothing.

Example

 Live Demo

<?php
   srand(mktime());
   echo(mt_rand());
?>

Output

664617053

Example

Let us see another example −

 Live Demo

<?php
   srand(2);
   echo(rand(1, 5));
?>

Output

4
raja
Published on 09-Nov-2018 17:36:52
Advertisements