srand() function in PHP



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
Updated on: 2019-12-27T10:01:04+05:30

206 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements