mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 13:57:03 +08:00
130 lines
5.5 KiB
HTML
130 lines
5.5 KiB
HTML
<!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>播下一个更好的随机数发生器种子</title>
|
|
</head>
|
|
<body class="docs"><div id="layout">
|
|
<div id="layout-content"><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> — <span class="dc-title">播下一个更好的随机数发生器种子</span></p>
|
|
|
|
</div>
|
|
<div class="refsect1 description" id="refsect1-function.mt-srand-description">
|
|
<h3 class="title">说明</h3>
|
|
<div class="methodsynopsis dc-description">
|
|
<span class="methodname"><strong>mt_srand</strong></span>
|
|
([ <span class="methodparam"><span class="type">int</span> <code class="parameter">$seed</code></span>
|
|
] ) : <span class="type"><span class="type void">void</span></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">Note</strong>: <span class="simpara">自 PHP 4.2.0 起,不再需要用
|
|
<span class="function"><a href="srand.html" class="function">srand()</a></span> 或 <span class="function"><strong>mt_srand()</strong></span>
|
|
给随机数发生器播种 ,因为现在是由系统自动完成的。</span></p></blockquote>
|
|
|
|
</div>
|
|
|
|
<div class="refsect1 parameters" id="refsect1-function.mt-srand-parameters">
|
|
<h3 class="title">参数</h3>
|
|
<p class="para">
|
|
<dl>
|
|
|
|
|
|
<dt>
|
|
<code class="parameter">seed</code></dt>
|
|
|
|
<dd>
|
|
|
|
<p class="para">
|
|
可选的种子值
|
|
</p>
|
|
</dd>
|
|
|
|
|
|
</dl>
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 returnvalues" id="refsect1-function.mt-srand-returnvalues">
|
|
<h3 class="title">返回值</h3>
|
|
<p class="para">
|
|
没有返回值。
|
|
</p>
|
|
</div>
|
|
|
|
|
|
<div class="refsect1 changelog" id="refsect1-function.mt-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>4.2.0</td>
|
|
<td>
|
|
The <code class="parameter">seed</code> becomes optional
|
|
and defaults to a random value if omitted.
|
|
</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">范例</h3>
|
|
<p class="para">
|
|
<div class="example" id="example-4136">
|
|
<p><strong>Example #1 <span class="function"><strong>mt_srand()</strong></span> 例子</strong></p>
|
|
<div class="example-contents">
|
|
<div class="phpcode"><pre><span style="color: #000000">
|
|
<span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// seed with microseconds<br /></span><span style="color: #007700">function </span><span style="color: #0000BB">make_seed</span><span style="color: #007700">()<br />{<br /> list(</span><span style="color: #0000BB">$usec</span><span style="color: #007700">, </span><span style="color: #0000BB">$sec</span><span style="color: #007700">) = </span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">' '</span><span style="color: #007700">, </span><span style="color: #0000BB">microtime</span><span style="color: #007700">());<br /> return (float) </span><span style="color: #0000BB">$sec </span><span style="color: #007700">+ ((float) </span><span style="color: #0000BB">$usec </span><span style="color: #007700">* </span><span style="color: #0000BB">100000</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 </span><span style="color: #007700">= </span><span style="color: #0000BB">mt_rand</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?></span>
|
|
</span>
|
|
</pre></div>
|
|
</div>
|
|
|
|
</div>
|
|
</p>
|
|
</div>
|
|
|
|
<div class="refsect1 seealso" id="refsect1-function.mt-srand-seealso">
|
|
<h3 class="title">参见</h3>
|
|
<p class="para">
|
|
<ul class="simplelist">
|
|
<li class="member"><span class="function"><a href="mt_rand.html" class="function" rel="rdfs-seeAlso">mt_rand()</a> - 生成更好的随机数</span></li>
|
|
<li class="member"><span class="function"><a href="mt_getrandmax.html" class="function" rel="rdfs-seeAlso">mt_getrandmax()</a> - 显示随机数的最大可能值</span></li>
|
|
<li class="member"><span class="function"><a href="srand.html" class="function" rel="rdfs-seeAlso">srand()</a> - 播下随机数发生器种子</span></li>
|
|
</ul>
|
|
</p>
|
|
</div>
|
|
|
|
</div></div></div></body></html> |