Three Steps to Using Random Numbers in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 16:06:33
Original
778 people have browsed it

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...
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