How can we generate the same sequence of random numbers in MySQL?

MySQLMySQLi Database

When invoked with an integer argument, RAND( ) uses that value to seed the random number generator. Each time you seed the generator with a given value, RAND( ) will produce the same sequence of random numbers. Following example will demonstrate it −

Example

mysql> Select RAND(1), RAND(1), Rand(1);
+---------------------+---------------------+---------------------+
| RAND(1)             | RAND(1)             | Rand(1)             |
+---------------------+---------------------+---------------------+
| 0.40540353712197724 | 0.40540353712197724 | 0.40540353712197724 |
+---------------------+---------------------+---------------------+
1 row in set (0.00 sec)
raja
Published on 20-Feb-2018 14:39:01
Advertisements