The RAND()
function returns a random float value
Figure 1 shows a visual representation of the RAND()
function.
RAND(value)
The RAND()
function takes a value as a parameter, which acts as a seed value.
This is an optional parameter.
The RAND()
function returns a random float value greater than or equal to 0 and less than 1.
If the value of the optional parameter is specified, then this function returns a repeatable sequence of random numbers.
The same seed values will produce the same random number.
-- without seed valueSELECT RAND();SELECT RAND();-- with seed value and it shows that two rand() functions-- with same seed value produce the same random numberSELECT RAND(10);SELECT RAND(10);-- rand() used with floor() to produce random integer-- 10<=number<=20SELECT FLOOR(10 + RAND()*(20-10+1))