RAND
Description
RAND()
function is a non-deterministic random number generation function that can return a random floating-point number in the range [0, 1), with a uniform distribution. This function has a wide range of applications in various random sampling, simulation, and probability calculation scenarios.
Return Type
This function returns a value of type DOUBLE
.
Usage Example
- Generate a random number:
Result Example:
- Generate a random number for each row in a table:
Result Example:
- Use with other numerical functions to generate a random number within a specified range:
Result Example:
- Used for randomly selecting records:
Result Example:
Notes
- The
RAND()
function generates a new random number each time it is called. - If you need repeatable random results, you can use
RAND(seed)
, whereseed
is an integer used to initialize the random number generator's seed. This way, the sequence of random numbers generated can remain consistent across multiple queries. For example:
- In some database management systems, the
RAND()
function may have different behaviors or limitations. Please refer to the relevant documentation for the specific system.