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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 27-Dec-2019

122 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements