One approach to achieve this would be to modify your MySQL query to include an additional sorting criteria that ensures that rows with the same name are distributed evenly throughout the output.
Here's an example query that accomplishes this:
SELECT * FROM my_table ORDER BY name, RAND();
This query sorts the rows by name first, and then by a random value generated by the RAND() function. The random value ensures that rows with the same name are distributed randomly throughout the output, rather than being grouped together.
Note that using RAND() function in the ORDER BY clause can be computationally expensive and may not scale well for large tables. If this is the case, you might consider using a different deterministic function, such as the MD5 hash of the name, to achieve a similar result.
SELECT * FROM my_table ORDER BY MD5(name), RAND();
This query sorts the rows by the MD5 hash of the name first, and then by a random value generated by the RAND() function. The MD5 hash ensures that rows with the same name are distributed evenly throughout the output, while the random value ensures that the order of the rows is randomized.