Short answer: randomly.
Long answer: Selecting based on specific attributes can improve the precision of a measurement. This is a technique called *blocking*.
Let’s say you’re running an A/B test. You have two versions of an application, A and B, that you want to compare. You’ll measure “time spent on the app” for each.
The attribute you know about your users is their age: They’re either “over 25" or “25 or younger”. The “over 25" crowd generally spends less time on the app.
If you assign users completely randomly to version A or B you might, by chance, have more “over 25” users seeing version A. These extra “over 25" users would bias downward the measurement of time spent — but you’d attribute that bias to version A. If you were to rerun the experiment you might, this time, assign more “over 25” users to version B. In that case you’d attribute to the bias to version B.
So sometimes the age attribute makes your measurement biased towards A and sometimes towards B. On average, it’s unbiased, thanks to randomization.
Unfortunately, there’s variability from run to run. You can mitigate that by assigning the same number of over-25 users to A as to B and
the same number of 25-or-younger users to A as to B. Then age-related variability will disappear.
That being said, when you select users from the over-25 group, you should select them randomly, and the same goes for the under-25 group. That way your experiment is still unbiased to all of the other factors that might affect time spent.