关于SQLite的伪随机数

--random() 的返回值范围是:[-2^63,(2^63)-1],而通常要的是最小为 0的随机数,于是就不能直接用了,解决办法:

select 2016*('0.'||case col>0 when 1 then col else -col end) result from(select random() col);

--返回值带小数。或者:

select case col>0 when 1 then col else -col end result from(select random()/(-9223372036854775808/2016) col);

--返回值不带小数。

--为啥网络上大都写成从 -9223372036854775808 到 9223372036854775807?对于不知道的人,数字含义淡了很多,比如我一开始只把它当是一个字符串型数字。

posted @ 2016-12-25 07:01  大胡子毛绒老头  阅读(1446)  评论(0编辑  收藏  举报