SQLite: Alternatives to MySQL's RAND() Function
SQLite lacks a native equivalent to MySQL's RAND() function for generating random numbers. However, there are alternative approaches to achieve similar functionality in SQLite.
One alternative is to use the RANDOM() function, which generates a random number between 0 and 1. While not as versatile as RAND(), it can be used to achieve limited randomization. For instance, the following query selects a random row from the table 'table':
SELECT * FROM table ORDER BY RANDOM() LIMIT 1;
To ensure that the randomness is consistent across different executions, it's recommended to seed the random number generator with a fixed value using the PRAGMA statement before the query:
PRAGMA random_seed(10);
The above is the detailed content of How Can I Generate Random Numbers in SQLite Without Using MySQL's RAND() Function?. For more information, please follow other related articles on the PHP Chinese website!