MySQL 8.4
RAND([seed])- [ ]optional part
- seed
- Generator seed: the same seed gives the same sequenceINTOptional
Return value
A floating-point number (DOUBLE) from 0 inclusive to 1 exclusive
Examples
Random number
MySQL 8.4
SELECT RAND();Repeatable number with a seed
MySQL 8.4
SELECT RAND(1);Random integer from 1 to 6
MySQL 8.4
SELECT FLOOR(1 + RAND() * 6);Random table row
MySQL 8.4
SELECT member_name
FROM FamilyMembers
ORDER BY RAND()
LIMIT 1;Details
A random integer from a to b inclusive is given by FLOOR(a + RAND() * (b - a + 1)). ORDER BY RAND() together with LIMIT picks random table rows.