How to use random numbers in PHP

WBOY
Release: 2016-08-08 09:33:38
Original
754 people have browsed it

How to use random numbers in PHP

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;

//Step 2: Initialize the random number generator using the seed
srand($seed);

//Step 3: Generate random numbers within the specified range
$random =rand(10,40);

The above introduces the method of using random numbers in PHP, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!