<?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 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.srand.php',
    1 => 'srand',
    2 => '播下随机数发生器种子',
  ),
  'up' => 
  array (
    0 => 'ref.random.php',
    1 => 'Random 函数',
  ),
  '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' => 'zh',
    '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">播下随机数发生器种子</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.srand-description">
  <h3 class="title">说明</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">
   使用 <code class="parameter">seed</code> 播下随机数发生器种子，或者没有指定 <code class="parameter">seed</code> 时，使用随时值。
  </p>

  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">不再需要用
<span class="function"><strong>srand()</strong></span> 或 <span class="function"><a href="function.mt-srand.php" class="function">mt_srand()</a></span>
给随机数发生器播种，因为现在是由系统自动完成的。</span></p></blockquote>
  <div class="caution"><strong class="caution">警告</strong>
 <p class="para">
  由于 Mt19937（“梅森旋转算法”）引擎仅接受 32 位整数作为种子，因此尽管 Mt19937 的范围为
  2<sup class="superscript">19937</sup>-1，但可能的随机序列数量仅限于 2<sup class="superscript">32</sup>（即 4,294,967,296）。
 </p>
 <p class="para">
  当依赖隐式或显式随机播种时，重复会出现得更早。根据生日问题，在少于 80,000 个随机生成的种子后，预计重复种子的概率为
  50%。在随机生成大约 30,000 个种子后，重复种子的概率为 10%。
 </p>
 <p class="para">
  This makes Mt19937 unsuitable for applications where duplicated sequences must not happen with
  more than a negligible probability.
  如果需要可重复的种子，<span class="classname"><a href="class.random-engine-xoshiro256starstar.php" class="classname">Random\Engine\Xoshiro256StarStar</a></span> 和
  <span class="classname"><a href="class.random-engine-pcgoneseq128xslrr64.php" class="classname">Random\Engine\PcgOneseq128XslRr64</a></span> 引擎都支持更大的种子，它们不太可能随机碰撞。如果不需要再现性，<span class="classname"><a href="class.random-engine-secure.php" class="classname">Random\Engine\Secure</a></span>
  引擎提供加密安全随机性。
 </p>
</div>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <span class="simpara">
    自 PHP 7.1.0 起，<span class="function"><strong>srand()</strong></span> 成为 <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">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">seed</code></dt>
     <dd>
      <p class="para">
       用线性同余生成器生成的值填充状态，该生成器使用解释为无符号 32 位整数的 <code class="parameter">seed</code> 进行播种。
      </p>
      <p class="para">
       如果省略 <code class="parameter">seed</code> 或为 <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>，则将使用随机无符号 32 位整数。
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.srand-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   没有返回值。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.srand-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.3.0</td>
       <td>
        <code class="parameter">seed</code> 现在可为 null。
       </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">成为</a> <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">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.rand.php" class="function" rel="rdfs-seeAlso">rand()</a> - 产生一个随机整数</span></li>
    <li><span class="function"><a href="function.getrandmax.php" class="function" rel="rdfs-seeAlso">getrandmax()</a> - 显示随机数最大的可能值</span></li>
    <li><span class="function"><a href="function.mt-srand.php" class="function" rel="rdfs-seeAlso">mt_srand()</a> - 播下一个更好的随机数发生器种子</span></li>
   </ul>
  </p>
 </div>

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