(PHP 3 >= 3.0.6, PHP 4, PHP 5)
用 seed 來給隨機數發生器播種。從 PHP 4.2.0 版開始,seed 參數變為可選項,當該項為空時,會被設為隨時數。
例子 1. mt_srand() 範例
<?php// seed with microsecondsfunction make_seed(){ list($usec, $sec) = explode(' ', microtime()); return (float) $sec + ((float) $usec * 100000);}mt_srand(make_seed());$randval = mt_rand();?>
注: 自 PHP 4.2.0 起,不再需要用 srand() 或 mt_srand() 函數給隨機數發生器播種,現已自動完成。
參見 mt_rand(),mt_getrandmax() 和 srand()。