RAND()

Overview

A description for this Function has not yet been added to this Documentation.

See also: Functions in 10.6 ES, in 10.5 ES, and in 10.4 ES

EXAMPLES

This generates a random value that ranges from 0 to 5, including 0 but not including 5:

SELECT RAND()*5; -- 1st call
+--------------------+
| RAND()*5           |
+--------------------+
| 1.5705801188671775 |
+--------------------+
SELECT RAND()*5; -- 2nd call
+--------------------+
| RAND()*5           |
+--------------------+
| 4.6110827425598012 |
+--------------------+
CREATE TABLE t (i INT);
INSERT INTO t VALUES (1), (2), (3);
-- Using a seed (5) makes the random sequence repeatable.
SELECT i, RAND(5) FROM t; -- 1st call
+------+---------------------+
| i    | RAND(5)             |
+------+---------------------+
|    1 | 0.40613597483014313 |
|    2 |  0.8745439358749836 |
|    3 | 0.15431178561813363 |
+------+---------------------+
SELECT i, RAND(5) FROM t; -- 2nd call
+------+---------------------+
| i    | RAND(5)             |
+------+---------------------+
|    1 | 0.40613597483014313 |
|    2 |  0.8745439358749836 |
|    3 | 0.15431178561813363 |
+------+---------------------+
SELECT * FROM t ORDER BY RAND(); -- 1st call
+------+
| i    |
+------+
|    2 |
|    1 |
|    3 |
+------+
SELECT * FROM t ORDER BY RAND(); -- 2nd call
+------+
| i    |
+------+
|    1 |
|    3 |
|    2 |
+------+

CHANGE HISTORY

Release Series

History

10.6 Enterprise

  • Present starting in MariaDB Enterprise Server 10.6.4-1.

10.5 Enterprise

  • Present starting in MariaDB Enterprise Server 10.5.3-1.

10.4 Enterprise

  • Present starting in MariaDB Enterprise Server 10.4.6-1.

EXTERNAL REFERENCES