Home > Backend Development > PHP Tutorial > mysql rand()中随机的解决办法

mysql rand()中随机的解决办法

WBOY
Release: 2016-06-13 13:49:37
Original
870 people have browsed it

求一个mysql rand()中随机的解决方法
我想通过这个语句select   sp.subID,sp.subName,sp.subImage   from   subproduct   sp,mainproduct   mp   where   mp.mainID=sp.mainID   and   mp.mainName= '$name '   order   by   rate   desc,time   desc   limit   4中找出的结果再随机显示呢!!请各位赐教啊

------解决方案--------------------
随机函数rand()

用这个生成一个数字,除以4再取余数,得到的数作为你的随机开始数不久OK了?

以下这个是我 在网上找到的,他的随机因素是当前时间的毫秒数

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

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

//第三步:生成指定范围内的随机数
$random =rand(10,40);
------解决方案--------------------
PHP5已经不需要种子

直接rand就行了
------解决方案--------------------
随机显示是指数据打乱再显示?
------解决方案--------------------
array_rand

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