Home > php教程 > php手册 > 探讨PHP函数mt_srand使用技巧

探讨PHP函数mt_srand使用技巧

WBOY
Release: 2016-06-13 11:10:45
Original
1419 people have browsed it

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()。


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template