Use random () to get the random number of data, but the result is not close to 1 2?

There are 1000 pieces of data in the

user_default_avatar table, but the result of the query is always greater than 500 instead of floating around 500?

select *
from user_default_avatar
order by rand()
limit 100;
Nov.03,2021

well, in fact, it has something to do with the id distribution density of the data. If the later number distribution density is large, it will result in a number greater than 1 answer 2.


this algorithm is not more efficient than the one you have been scolded. Aren't you afraid of being scolded again?
both methods need to calculate a random number for each row, and your new statement may not be as fast as before.

Menu