To generate a pseudorandom floating point number between
1, use the
Suppose you have the following query
SELECT i, RAND() FROM t;
This will return something like this
To generate a random number in the range a <= n <= b, you can use the following formula
FLOOR(a + RAND() * (b - a + 1))
For example, this will generate a random number between 7 and 12
SELECT FLOOR(7 + (RAND() * 6));
A simple way to randomly return the rows in a table:
SELECT * FROM tbl ORDER BY RAND();
These are pseudorandom numbers.
The pseudorandom number generator in MySQL is not cryptographically secure. That is, if you use MySQL to generate random numbers to be used as secrets, a determined adversary who knows you used MySQL will be able to guess your secrets more easily than you might believe.