(PHP 4, PHP 5)
mt_srand — 播下一個更好的隨機數發生器種子
說明
void mt_srand ([ int$seed
] )
用
seed
來給隨機數發生器播種。 沒有設定 seed
參數時,會被設為隨時數。
Note: 自 PHP 4.2.0 起,不再需要用 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.
范例
Example #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();
?>
參見
mt_rand() - 生成更好的隨機數 mt_getrandmax() - 顯示隨機數的最大可能值 srand() - 播下隨機數發生器種子