Sophie

Sophie

distrib > Mageia > 7 > armv7hl > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 4874

php-manual-en-7.2.11-1.mga7.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Seeds the Mersenne Twister Random Number Generator</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mt-rand.html">mt_rand</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.octdec.html">octdec</a></div>
 <div class="up"><a href="ref.math.html">Math Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mt-srand" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mt_srand</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">mt_srand</span> &mdash; <span class="dc-title">Seeds the Mersenne Twister Random Number Generator</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.mt-srand-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><span class="type void">void</span></span> <span class="methodname"><strong>mt_srand</strong></span>
    ([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$seed</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$mode</code><span class="initializer"> = MT_RAND_MT19937</span></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"><a href="function.srand.html" class="function">srand()</a></span> or
<span class="function"><strong>mt_srand()</strong></span> as this is done automatically.
</span></p></blockquote>
  
 </div>

 <div class="refsect1 parameters" id="refsect1-function.mt-srand-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">seed</code></dt>

     <dd>

      <p class="para">
       An arbitrary <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span> seed value.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">mode</code></dt>

     <dd>

      <p class="para">
       Use one of the following constants to specify the implementation of the algorithm to use.
       <table class="doctable informaltable">
        
         <thead>
          <tr>
           <th>Constant</th>
           <th>Description</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><strong><code>MT_RAND_MT19937</code></strong></td>
           <td>
            Uses the fixed, correct, Mersenne Twister implementation, available as of PHP 7.1.0.
           </td>
          </tr>

          <tr>
           <td><strong><code>MT_RAND_PHP</code></strong></td>
           <td>
            Uses an incorrect Mersenne Twister implementation which was used as the default up till PHP 7.1.0. 
            This mode is available for backward compatibility.
           </td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    
   </dl>

  </p>
 </div>

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

 
 <div class="refsect1 changelog" id="refsect1-function.mt-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>7.1.0</td>
       <td>
        <span class="function"><a href="function.srand.html" class="function">srand()</a></span> <a href="migration71.incompatible.html#migration71.incompatible.rand-srand-aliases" class="link">has been made</a> an alias of <span class="function"><strong>mt_srand()</strong></span>.
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        <span class="function"><a href="function.mt-rand.html" class="function">mt_rand()</a></span> <a href="migration71.incompatible.html#migration71.incompatible.fixes-to-mt_rand-algorithm" class="link">has been updated</a> to use the fixed, correct, version of
         the Mersenne Twister algorithm. To fall back to the old behaviour, use <span class="function"><strong>mt_srand()</strong></span> with <strong><code>MT_RAND_PHP</code></strong> as the second paramter.
       </td>
      </tr>

      <tr>
       <td>5.2.1</td>
       <td>
        The Mersenne Twister implementation in PHP now uses a new seeding
        algorithm by Richard Wagner. Identical seeds no longer produce the same
        sequence of values they did in previous versions. This behavior is not
        expected to change again, but it is considered unsafe to rely upon it
        nonetheless.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.mt-srand-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-4264">
    <p><strong>Example #1 <span class="function"><strong>mt_srand()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;seed&nbsp;with&nbsp;microseconds<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">make_seed</span><span style="color: #007700">()<br />{<br />&nbsp;&nbsp;list(</span><span style="color: #0000BB">$usec</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sec</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">'&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">microtime</span><span style="color: #007700">());<br />&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$sec&nbsp;</span><span style="color: #007700">+&nbsp;</span><span style="color: #0000BB">$usec&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">1000000</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">mt_srand</span><span style="color: #007700">(</span><span style="color: #0000BB">make_seed</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">$randval&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mt_rand</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.mt-srand-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.mt-rand.html" class="function" rel="rdfs-seeAlso">mt_rand()</a> - Generate a random value via the Mersenne Twister Random Number Generator</span></li>
    <li class="member"><span class="function"><a href="function.mt-getrandmax.html" class="function" rel="rdfs-seeAlso">mt_getrandmax()</a> - Show largest possible random value</span></li>
    <li class="member"><span class="function"><a href="function.srand.html" class="function" rel="rdfs-seeAlso">srand()</a> - Seed the random number generator</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mt-rand.html">mt_rand</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.octdec.html">octdec</a></div>
 <div class="up"><a href="ref.math.html">Math Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>