FASTRAND()

Overview

Returns a non-negative 64-bit random integer.

USAGE

FASTRAND()

DETAILS

FASTRAND() is a mathematical function that returns a random non-negative 64-bit integer.

To convert the value into a smaller range of values, consider using % or (for powers of 2) &.

SYNONYMS

SCHEMA

PARAMETERS

SKYSQL

PRIVILEGES

EXAMPLES

This generates two random integer values, the first that ranges from 1 to 5 (inclusive) and the second that ranges from 11 to 18 (inclusive):

SELECT (FASTRAND() % 5) + 1 AS '1st run 1..5',
       (FASTRAND() & 7) + 11 AS '11..18';
+--------------+--------+
| 1st run 1..5 | 11..18 |
+--------------+--------+
|            2 |     16 |
+--------------+--------+
SELECT (FASTRAND() % 5) + 1 AS '2nd run 1..5',
       (FASTRAND() & 7) + 11 AS '11..18';
+--------------+--------+
| 2nd run 1..5 | 11..18 |
+--------------+--------+
|            5 |     13 |
+--------------+--------+
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 FASTRAND();
+---------+
| 1st run |
+---------+
| two     |
| one     |
| three   |
+---------+
SELECT x AS '2nd run'
 FROM rand_example
 ORDER BY FASTRAND();
+---------+
| 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