RAND
Description
RAND() function is a non-deterministic function used to generate a random number in the range [0,1). Each time this function is called, it returns a uniformly distributed random floating-point number, ranging from 0 (inclusive) to 1 (exclusive).
Return Type
The result type returned by this function is a double-precision floating-point number (double).
Example
- Generate and display a random number:
The result may look like this:
- Generate a random weight for each record in a table:
Suppose there is a table named
productswith the following columns:id(product ID),name(product name), andweight(product weight). You can use theRAND()function to generate a random weight for each product:
The result may look like this:
