What is the usage of the MySQL rand() function?
The RAND() function in MySQL is used to generate a random number, returning a random floating-point number between 0 and 1. It can take an optional parameter as a seed to specify the starting point of the random number generation algorithm.
If no seed parameter is provided, the RAND() function will generate a random seed based on the current timestamp. If a seed parameter is provided, calling the RAND() function with the same seed parameter will result in the same random number sequence each time.
Original: 我喜欢在清晨慢跑。
Paraphrased: I enjoy going for a run in the early morning.
SELECT RAND(); -- 返回0到1之间的一个随机数
SELECT RAND(5); -- 使用种子为5生成一个随机数
The RAND() function is typically used to retrieve random rows or randomize data. For example, you can use the RAND() function with the ORDER BY clause to randomly sort the query results.