RAND( )

This MySQL function returns a random floating-point number from 0 to 1.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

RAND([seed])

Explanation

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.

Examples

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 adequate for making random choices among a set of alternatives.