rand() 是 MySQL 的数学函数。该函数用于生成随机数。
语法
select rand();
返回
此函数返回一个随机数或一个范围内的随机数。
示例 1
Select rand();
输出:
mysql> Select rand();
+------------------+
| rand() |
+------------------+
| 0.83306165023992 |
+------------------+
1 row in set (0.00 sec)
+------------------+
| rand() |
+------------------+
| 0.83306165023992 |
+------------------+
1 row in set (0.00 sec)
示例 2
select rand()*3;
输出:
mysql> select rand()*3;
+--------------------+
| rand()*3 |
+--------------------+
| 1.4031195588438954 |
+--------------------+
1 row in set (0.01 sec)
+--------------------+
| rand()*3 |
+--------------------+
| 1.4031195588438954 |
+--------------------+
1 row in set (0.01 sec)
示例 3
Select rand()-0.4;
输出:
mysql> Select rand()-0.4;
+--------------------+
| rand()-0.4 |
+--------------------+
| 0.4393476780870442 |
+--------------------+
1 row in set (0.00 sec)