//摘自手册 RAND() RAND(N) 返回一个随机浮点值 v ,范围在 0 到1 之间 (即, 其范围为 0 ≤ v ≤ 1.0)。若已指定一个整数参数 N ,则它被用作种子值,用来产生重复序列。
有两个方法可以达成以上效果. 1.新建一个表,里面存着 -5 至 5 之间的数.再利用order by rand()得到随机数.
#建立指定范围数据表 #auther: 小强(占卜师) #date: 2008-03-31
create table randnumber select -1 as number union select -2 union select -3 union select -4 union select -5 union select 0 union select 1 union select 2 union select 3 union select 4 union select 5
#得到随机数 #auther: 小强(占卜师) #date: 2008-03-31
select number from randnumber order by rand() limit 1