Heim  >  Artikel  >  Backend-Entwicklung  >  探讨PHP函数mt_srand使用技巧_PHP教程

探讨PHP函数mt_srand使用技巧_PHP教程

WBOY
WBOYOriginal
2016-07-15 13:33:471205Durchsuche

PHP函数mt_srand说明

void mt_srand ( int seed )

用 seed 来给随机数发生器播种。从 PHP 4.2.0 版开始,seed 参数变为可选项,当该项为空时,会被设为随时数。

例子 1. PHP函数mt_srand 范例

  1.  ?php  
  2. // seed with microseconds  
  3. function make_seed()  
  4. {  
  5. list($usec, $sec) = explode
    (' ', microtime());  
  6. return (float) $sec + 
    ((float) $usec * 100000);  
  7. }  
  8. mt_srand(make_seed());  
  9. $randval = mt_rand();  
  10. ?>   

注: 自 PHP 4.2.0 起,不再需要用 srand() 或PHP函数mt_srand给随机数发生器播种,现已自动完成。
参见 mt_rand(),mt_getrandmax() 和 srand()。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/446043.htmlTechArticlePHP函数mt_srand说明 void mt_srand ( int seed ) 用 seed 来给随机数发生器播种。从 PHP 4.2.0 版开始,seed 参数变为可选项,当该项为空时,会被设为随...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn