MySQL RAND function is one of the Mathematical Functions used to return or generate the random numbers between 0 and 1. The syntax of the RAND in MySQL is as shown below:
Generally, this RAND function generates numbers between 0.0 to 1.0. However, if you want a random integer, then you have to follow the below technique.
SELECT FLOOR(10 + RAND() * 30);
This generates the random integer number between 10 and 30.
MySQL RAND Function Example 1
The MySQL Random Function returns the random values. The following query shows multiple ways to use the RAND function.
SELECT RAND(10), RAND(120), RAND(-150);
MySQL RAND Example 2
The Random Function also allows you to return or store random values inside a column. In this Mathematical Function example, we are generating random numbers for each employee in a customer table. Please refer to In this Mathematical Function in MySQL.
SELECT EmpID, FirstName, LastName, Occupation, RAND(), RAND(5), RAND(10) FROM customer;