RAND()

Overview

Returns a random non-negative floating-point number less than 1.

USAGE

RAND()

DETAILS

RAND() is a mathematical function that returns a random non-negative floating-point number less than 1.

To generate a random integer value in the range x .. y (inclusive) you can multiply the returned value by (y - x + 1), convert the value to an integer, and add x.

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

This generates a random integer value that ranges from 1 to 5 (inclusive):

SELECT FLOOR(RAND()*5) + 1 AS '1st run';
+---------+
| 1st run |
+---------+
|       2 |
+---------+
SELECT FLOOR(RAND()*5) + 1 AS '2nd run';
+---------+
| 2nd run |
+---------+
|       5 |
+---------+
CREATE TABLE rand_example (
  x VARCHAR(10)
);
INSERT INTO rand_example VALUES
  ('one'), ('two'), ('three');
SELECT x AS '1st run'
FROM rand_example
ORDER BY RAND();
+---------+
| 1st run |
+---------+
| two     |
| one     |
| three   |
+---------+
SELECT x AS '2nd run'
 FROM rand_example
 ORDER BY RAND();
+---------+
| 2nd run |
+---------+
| one     |
| three   |
| two     |
+---------+

ERROR HANDLING

FEATURE INTERACTION

RESPONSES

DIAGNOSIS

ISO 9075:2016

CHANGE HISTORY

Release Series

History

23.09

  • Present starting in MariaDB Xpand 23.09.1.

6.1

  • Present starting in MariaDB Xpand 6.1.0.

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.0

  • Present starting in MariaDB Xpand 6.0.3.

5.3

  • Present starting in MariaDB Xpand 5.3.13.

Release Series

History

6.1

  • Present starting in MariaDB Xpand 6.1.0.

EXTERNAL REFERENCES