Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 5915

php-manual-en-5.5.7-1.mga4.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>Seed the 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.sqrt.html">sqrt</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.tan.html">tan</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.srand" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">srand</h1>
  <p class="verinfo">(PHP 4, PHP 5)</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="type"><span class="type void">void</span></span> <span class="methodname"><strong>srand</strong></span>
     ([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$seed</code></span>
   ] )</div>

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

  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">As of PHP 4.2.0, 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.html" class="function">mt_srand()</a></span> as this is now done automatically.
</span></p></blockquote>

 </div>

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

    <dt>

     <span class="term"><em><code class="parameter">seed</code></em></span>
     <dd>

      <p class="para">
       Optional seed value
      </p>
     </dd>

    </dt>

   </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>4.2.0</td>
       <td>
        The <em><code class="parameter">seed</code></em> becomes optional
        and defaults to a random value if omitted.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.srand-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-3479">
    <p><strong>Example #1  <span class="function"><strong>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;(float)&nbsp;</span><span style="color: #0000BB">$sec&nbsp;</span><span style="color: #007700">+&nbsp;((float)&nbsp;</span><span style="color: #0000BB">$usec&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">100000</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">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">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.srand-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.rand.html" class="function" rel="rdfs-seeAlso">rand()</a> - Generate a random integer</span></li>
    <li class="member"> <span class="function"><a href="function.getrandmax.html" class="function" rel="rdfs-seeAlso">getrandmax()</a> - Show largest possible random value</span></li>
    <li class="member"> <span class="function"><a href="function.mt-srand.html" class="function" rel="rdfs-seeAlso">mt_srand()</a> - Seed the better 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.sqrt.html">sqrt</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.tan.html">tan</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>