Home  >  Article  >  Backend Development  >  Three Steps to Using Random Numbers in PHP_PHP Tutorial

Three Steps to Using Random Numbers in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 16:06:33780browse

I want to make a web page that appears randomly, but using rand() doesn't work. I heard that random numbers need to be initialized, but how to initialize them? Please give me some advice, thank you!

//The first step: initialize the seed
$seedarray =microtime();
$seedstr =split(" ",$seedarray,5);
$seed =$seedstr[ 0]*10000;

//The second step: Initialize the random number generator using the seed
srand($seed);

//The third step: Generate a random number generator within the specified range Random number
$random =rand(10,40);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315427.htmlTechArticleI want to make a web page that appears randomly, but using rand() doesn’t work. I heard that random numbers need to be initialized. , but please feel free to enlighten me on how to initialize it, thank you! //The first step: initialize the seed...
Statement:
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