FASTRAND()
This page is part of MariaDB's Documentation.
The parent of this page is: Functions for MariaDB Xpand
Topics on this page:
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) &.
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 |
+---------+