RAND()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Enterprise Server
Topics on this page:
Overview
A description for this Function has not yet been added to this Documentation.
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
EXTERNAL REFERENCES
Additional information on this topic may be found in the MariaDB Public Knowledge Base.