(PHP 4, PHP 5, PHP 7, PHP 8)
mt_srand — 播下一個更好的隨機數(shù)發(fā)生器種子
$seed
= ?): void
用
seed
來給隨機數(shù)發(fā)生器播種。 沒有設(shè)定 seed
參數(shù)時,會被設(shè)為隨時數(shù)。
注意: 不再需要用 srand() 或 mt_srand() 給隨機數(shù)發(fā)生器播種,因為現(xiàn)在是由系統(tǒng)自動完成的。
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();
?>