# I am calling RAND() function two times in the same query then will it generate same random number two times or will it generate two different random numbers?

MySQLMySQLi Database

We know that MySQL RAND() returns a random floating point value between the range of 0 and 1. It will generate two different random numbers if we will call the RAND() function, without seed, two times in the same query. Following example will make it clearer −

## Example

mysql> Select RAND(), RAND(), Rand();
+--------------------+-------------------+--------------------+
| RAND()             | RAND()            | Rand()             |
+--------------------+-------------------+--------------------+
| 0.9402844448949066 | 0.911499003797303 | 0.7366417150354402 |
+--------------------+-------------------+--------------------+
1 row in set (0.00 sec)


The above result set shows that RAND() function will generate different random number every time we call it.

Published on 20-Feb-2018 14:28:22