5 ms·
I like the question. Not sure how id do it. As a one off of the table is not too big id get all the IDs then write a program to pick 1000 at random. I assume ra
by bravesoul2 1y ago
I like the question. Not sure how id do it. As a one off of the table is not too big id get all the IDs then write a program to pick 1000 at random. I assume randomness is more important than expense but that can be a clarifying question to the interviewer.
If this query had to be done regularly for A B testing or whatever I might suggest a salted hash. Given an id you hash and do a Bitcoin style "is it lower than X". Figure out X based on total user count and desired sample. This way you can tell if a user is in the set without looking at other records. You can also handle the user count growing or shrinking. But the trade off is rough numbers over exact numbers.