Home > Backend Development > PHP Tutorial > Discuss the usage skills of PHP function mt_srand_PHP tutorial

Discuss the usage skills of PHP function mt_srand_PHP tutorial

WBOY
Release: 2016-07-15 13:33:47
Original
1274 people have browsed it

PHP function mt_srand description

void mt_srand (int seed)

Use seed to give Random number generator seeding. Starting from PHP version 4.2.0, the seed parameter becomes optional, and when it is empty, it will be set to a constant.

Example 1. PHP function mt_srand example

  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. ?>
Note: Since PHP 4.2.0, it is no longer necessary to seed the random number generator with srand() or the PHP function mt_srand, it is now done automatically.

See mt_rand(), mt_getrandmax() and srand().



http://www.bkjia.com/PHPjc/446043.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446043.htmlTechArticlePHP function mt_srand description void mt_srand (int seed) Use seed to seed the random number generator. Starting from PHP version 4.2.0, the seed parameter becomes optional. When it is empty, it will be set to random...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template