mt_srand
(PHP 4, PHP 5, PHP 7, PHP 8)
mt_srand — 播下一個更好的隨機數發生器種子
說明
mt_srand(int
$seed
= ?): void
用
seed
來給隨機數發生器播種。 沒有設定 seed
參數時,會被設為隨時數。
注意: 不再需要用 srand() 或 mt_srand() 給隨機數發生器播種,因為現在是由系統自動完成的。
參數
-
seed
-
可選的種子值
返回值
沒有返回值。
更新日誌
版本 | 說明 |
---|---|
4.2.0 |
The seed becomes optional
and defaults to a random value if omitted.
|
5.2.1 | 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. |
範例
示例 #1 mt_srand() 例子
<?php
// seed with microseconds
function make_seed()
{
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
mt_srand(make_seed());
$randval = mt_rand();
?>