⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.mt-rand.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Generate a better random value</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mt-getrandmax.html">mt_getrandmax</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mt-srand.html">mt_srand</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-rand" class="refentry"> <div class="refnamediv">  <h1 class="refname">mt_rand</h1>  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">mt_rand</span> &mdash; <span class="dc-title">Generate a better random value</span></p> </div> <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">int</span> <span class="methodname"><b><b>mt_rand</b></b></span>    ( <span class="methodparam">void</span>   )</div>  <div class="methodsynopsis dc-description">   <span class="type">int</span> <span class="methodname"><b><b>mt_rand</b></b></span>    ( <span class="methodparam"><span class="type">int</span> <tt class="parameter">$min</tt></span>   , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$max</tt></span>   )</div>  <p class="simpara">   Many random number generators of older libcs have dubious or   unknown characteristics and are slow. By default, PHP uses the   libc random number generator with the <a href="function.rand.html" class="function">rand()</a>   function.  The <b>mt_rand()</b> function is a drop-in   replacement for this.  It uses a random number generator with   known characteristics using the <a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html" class="link external">&raquo;    Mersenne Twister</a>, which will produce random numbers four times   faster than what the average libc rand() provides.  </p>  <p class="simpara">   If called without the optional <i><tt class="parameter">min</tt></i>,   <i><tt class="parameter">max</tt></i> arguments <b>mt_rand()</b>   returns a pseudo-random value between 0 and   <a href="function.mt-getrandmax.html" class="function">mt_getrandmax()</a>.  If you want a random number   between 5 and 15 (inclusive), for example, use <i>mt_rand(5,   15)</i>.  </p>  <blockquote><p><b class="note">Note</b>: <span class="simpara">As of PHP 4.2.0, there is no need to seed the random number generator with <a href="function.srand.html" class="function">srand()</a> or <a href="function.mt-srand.html" class="function">mt_srand()</a> as this is now done automatically.</span></p></blockquote> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">min</tt></i></span>     <dd>      <p class="para">       Optional lowest value to be returned (default: 0)      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">max</tt></i></span>     <dd>      <p class="para">       Optional highest value to be returned (default: <a href="function.mt-getrandmax.html" class="function">mt_getrandmax()</a>)      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   A random integer value between <i><tt class="parameter">min</tt></i> (or 0)   and <i><tt class="parameter">max</tt></i> (or <a href="function.mt-getrandmax.html" class="function">mt_getrandmax()</a>, inclusive)  </p> </div> <div class="refsect1 changelog">  <h3 class="title">ChangeLog</h3>  <p class="para">   <table class="informaltable">    <colgroup>     <thead valign="middle">      <tr valign="middle">       <th colspan="1">Version</th>       <th colspan="1">Description</th>      </tr>     </thead>     <tbody valign="middle" class="tbody">      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">Since 3.0.7</td>       <td colspan="1" rowspan="1" align="left">        In versions before 3.0.7 the meaning of        <i><tt class="parameter">max</tt></i> was <i><tt class="parameter">range</tt></i>. To        get the same results in these versions the short example should        be <i>rand (5, 11)</i> to get a random number        between 5 and 15.       </td>      </tr>     </tbody>    </colgroup>   </table>  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>mt_rand()</b> example</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">mt_rand</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">mt_rand</span><span style="color: #007700">()&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />echo&nbsp;</span><span style="color: #0000BB">mt_rand</span><span style="color: #007700">(</span><span style="color: #0000BB">5</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">15</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>    <div class="example-contents"><p>The above example will output something similar to:</p></div>    <div class="example-contents"><pre><div class="cdata"><pre>160471601414786132786</pre></div>    </pre></div>   </div>  </p> </div> <div class="refsect1 seealso">  <h3 class="title">See Also</h3>  <p class="para">   <ul class="simplelist">    <li class="member"><a href="function.mt-srand.html" class="function" rel="rdfs-seeAlso">mt_srand()</a></li>    <li class="member"><a href="function.mt-getrandmax.html" class="function" rel="rdfs-seeAlso">mt_getrandmax()</a></li>    <li class="member"><a href="function.rand.html" class="function" rel="rdfs-seeAlso">rand()</a></li>   </ul>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.mt-getrandmax.html">mt_getrandmax</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.mt-srand.html">mt_srand</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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -