RAND()

USAGE

DETAILS

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

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 |
+------+

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.08 Enterprise

  • Present starting in MariaDB Enterprise Server 23.08.0.

23.07 Enterprise

  • Present starting in MariaDB Enterprise Server 23.07.0.

10.6 Enterprise

  • Present starting in MariaDB Enterprise Server 10.6.4-1.

10.6 Community

  • Present starting in MariaDB Community Server 10.6.0.

10.5 Enterprise

  • Present starting in MariaDB Enterprise Server 10.5.3-1.

10.5 Community

  • Present starting in MariaDB Community Server 10.5.0.

10.4 Enterprise

  • Present starting in MariaDB Enterprise Server 10.4.6-1.

10.4 Community

  • Present starting in MariaDB Community Server 10.4.0.

10.3 Enterprise

  • Present starting in MariaDB Enterprise Server 10.3.16-1.

10.3 Community

  • Present starting in MariaDB Community Server 10.3.0.

10.2 Enterprise

  • Present starting in MariaDB Enterprise Server 10.2.25-1.

10.2 Community

  • Present starting in MariaDB Community Server 10.2.0.

Release Series

History

23.08 Enterprise

  • Present starting in MariaDB Enterprise Server 23.08.0.

23.07 Enterprise

  • Present starting in MariaDB Enterprise Server 23.07.0.

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