Home >php教程 >php手册 >在 PHP 中使用随机数的三个步骤

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

WBOY
WBOYOriginal
2016-06-13 12:41:47810browse

我想做一个随机的出现的网页,可是用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
Previous article:Php+SqlServer实现分页显示Next article:也谈 PHP 和 MYSQL