srand() function in PHP

PHPProgrammingServer Side Programming

<p>The mt_srand() function seeds the random number generator.</p><p><strong>Note</strong> &minus; Random number generator is seeded automatically after the release of PHP 4.2.0. This function is not needed now.</p><h2>Syntax</h2><pre class="result notranslate">srand(seed)</pre><h2>Parameters</h2><ul class="list"><li><p><strong>seed</strong> &minus; The seed value</p></li></ul><h2>Return</h2><p>The srand() function Returns nothing.</p><h2>Example</h2><p><a class="demo" href="http://tpcg.io/9pBE1U" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate">&lt;?php &nbsp; &nbsp;srand(mktime()); &nbsp; &nbsp;echo(mt_rand()); ?&gt;</pre><h2>Output</h2><pre class="result notranslate">664617053</pre><h2>Example</h2><p>Let us see another example &minus;</p><p><a class="demo" href="http://tpcg.io/pXqorF" rel="nofollow" target="_blank">&nbsp;Live Demo</a></p><pre class="prettyprint notranslate">&lt;?php &nbsp; &nbsp;srand(2); &nbsp; &nbsp;echo(rand(1, 5)); ?&gt;</pre><h2>Output</h2><pre class="result notranslate">4</pre>
raja
Updated on 27-Dec-2019 10:01:04

Advertisements