如何获得MySQL随机整数范围?

我试图生成一个随机的整数,我select1和60之间的每一行作为计时器。

SELECT downloads.date, products.*, (FLOOR(1 + RAND() * 60)) AS timer 

我已经search并继续来到这个FLOOR函数,如何select一个范围内的随机整数。 这是给我一个每行1。 我错过了什么?

我在MySQL 5.0.75

inheritance人其余的查询我相信这可能是一个嵌套问题

 SELECT * FROM ( SELECT downloads.date, products.*, FLOOR(1 + (RAND() * 60)) AS randomtimer, ( SELECT COUNT( * ) FROM distros WHERE distros.product_id = products.product_id ) AS distro_count, (SELECT COUNT(*) FROM downloads WHERE downloads.product_id = products.product_id) AS true_downloads FROM downloads INNER JOIN products ON downloads.product_id = downloads.product_id ) AS count_table WHERE count_table.distro_count > 0 AND count_table.active = 1 ORDER BY count_table.randomtimer , count_table.date DESC LIMIT 10 

这是为我工作。 你的mysql版本可能?

 SELECT id, (FLOOR( 1 + RAND( ) *60 )) AS timer FROM users LIMIT 0 , 30 

我正在运行您的查询,它确实给了我每行的随机数….也许有什么与随机(定时器)的名称?

RAND函数的输出将始终是介于01之间的值。

尝试这个:

 SELECT downloads.date, products.*, (CAST(RAND() * 60 AS UNSIGNED) + 1) AS timer 

您可以增加数字乘以表中的logging数。

 SELECT id, (FLOOR( (SELECT MIN(id) FROM your_table ) + RAND( ) * 1000000 ) ) AS timer FROM your_table LIMIT 0 , 30