Home >Backend Development >PHP Tutorial >在PHP中使用随机数的三个步骤_PHP

在PHP中使用随机数的三个步骤_PHP

WBOY
WBOYOriginal
2016-06-01 12:41:38992browse

我想做一个随机的出现的网页,可是用rand()就是不行,听说要初始化随机数,可是怎么初始化,请不吝赐教,谢谢!

//第一步:初始化种子
$seedarray =microtime();
$seedstr =split(" ",$seedarray,5);
$seed =$seedstr[0]*10000;

//第二步:使用种子初始化随机数发生器
srand($seed);

//第三步:生成指定范围内的随机数
$random =rand(10,40); 

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