<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.random.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.srand.php',
    1 => 'srand',
    2 => 'Seed the random number generator',
  ),
  'up' => 
  array (
    0 => 'ref.random.php',
    1 => 'Random Functions',
  ),
  'prev' => 
  array (
    0 => 'function.random-int.php',
    1 => 'random_int',
  ),
  'next' => 
  array (
    0 => 'class.random-randomizer.php',
    1 => 'Random\\Randomizer',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/random/functions/srand.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.srand" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">srand</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">srand</span> &mdash; <span class="dc-title">Seed the random number generator</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.srand-description">
  <h3 class="title">Description</h3>
   <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>srand</strong></span>(<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$seed</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$mode</code><span class="initializer"> = <strong><code><a href="random.constants.php#constant.mt-rand-mt19937">MT_RAND_MT19937</a></code></strong></span></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  <p class="para rdfs-comment">
   Seeds the random number generator with
   <code class="parameter">seed</code> or with a random value
   if no <code class="parameter">seed</code> is given.
  </p>

  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">There is no need
to seed the random number generator with <span class="function"><strong>srand()</strong></span> or
<span class="function"><a href="function.mt-srand.php" class="function">mt_srand()</a></span> as this is done automatically.
</span></p></blockquote>
  <div class="caution"><strong class="caution">Caution</strong>
 <p class="para">
  Because the Mt19937 (“Mersenne Twister”) engine accepts only a single 32 bit integer as the
  seed, the number of possible random sequences is limited to just 2<sup class="superscript">32</sup>
  (i.e. 4,294,967,296), despite Mt19937’s huge period of 2<sup class="superscript">19937</sup>-1.
 </p>
 <p class="para">
  When relying on either implicit or explicit random seeding, duplications will appear
  much earlier. Duplicated seeds are expected with 50% probability after less than
  80,000 randomly generated seeds according to the birthday problem. A 10% probability
  of a duplicated seed happens after randomly generating roughly 30,000 seeds.
 </p>
 <p class="para">
  This makes Mt19937 unsuitable for applications where duplicated sequences must not happen with
  more than a negligible probability. If reproducible seeding is required, both the
  <span class="classname"><a href="class.random-engine-xoshiro256starstar.php" class="classname">Random\Engine\Xoshiro256StarStar</a></span> and <span class="classname"><a href="class.random-engine-pcgoneseq128xslrr64.php" class="classname">Random\Engine\PcgOneseq128XslRr64</a></span>
  engines support much larger seeds that are unlikely to collide randomly. If reproducibility
  is not required, the <span class="classname"><a href="class.random-engine-secure.php" class="classname">Random\Engine\Secure</a></span> engine provides cryptographically
  secure randomness.
 </p>
</div>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">As of PHP 7.1.0, <span class="function"><strong>srand()</strong></span> has been made
   an alias of <span class="function"><a href="function.mt-srand.php" class="function">mt_srand()</a></span>.</span>
  </p></blockquote>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.srand-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">seed</code></dt>
     <dd>
      <p class="para">
       Fills the state with values generated with a linear congruential generator
       that was seeded with <code class="parameter">seed</code> interpreted as an unsigned
       32 bit integer.
      </p>
      <p class="para">
       If <code class="parameter">seed</code> is omitted or <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, a random unsigned
       32-bit integer will be used.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.srand-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   No value is returned.
  </p>
 </div>

 <div class="refsect1 changelog" id="refsect1-function.srand-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.3.0</td>
       <td>
        <code class="parameter">seed</code> is now nullable.
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        <span class="function"><strong>srand()</strong></span> <a href="migration71.incompatible.php#migration71.incompatible.rand-srand-aliases" class="link">has been made</a> an alias of <span class="function"><a href="function.mt-srand.php" class="function">mt_srand()</a></span>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.srand-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.rand.php" class="function" rel="rdfs-seeAlso">rand()</a> - Generate a random integer</span></li>
    <li><span class="function"><a href="function.getrandmax.php" class="function" rel="rdfs-seeAlso">getrandmax()</a> - Show largest possible random value</span></li>
    <li><span class="function"><a href="function.mt-srand.php" class="function" rel="rdfs-seeAlso">mt_srand()</a> - Seeds the Mersenne Twister Random Number Generator</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>