How can the ORDER BY RAND() function in MySQL be optimized for better randomization of data?

The ORDER BY RAND() function in MySQL can be slow for large datasets as it has to generate a random number for each row and then sort the data based on those numbers. To optimize this for better randomization, you can use a combination of RAND() and a subquery to assign a random number to each row and then order by that number.

SELECT * FROM table_name
ORDER BY RAND();
```

```php
SELECT * FROM (
    SELECT *, RAND() as random_num FROM table_name
) AS sub
ORDER BY sub.random_num;