Name

RAND()

Synopsis

RAND([seed])

This function returns a random floating-point number from 0 to 1. A seed number may be passed as an argument to start the sequence of random numbers at a different point. Here is an example:

SELECT RAND( ), RAND( );

+------------------+------------------+
| RAND( )          | RAND( )          |
+------------------+------------------+
| 0.29085519843814 | 0.45449978900561 |
+------------------+------------------+

Note that rerunning this statement with the same seed will produce the same results. This type of sequence is properly known as a pseudorandom number generator, and is generally not considered strong enough for security purposes, but it is adequate for making random choices among a set of alternatives.

Get MySQL in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.