Removing a fixed quantity from multiple "buckets" randomly Suppose I have a set of $100$ elements split into $4$ buckets A-D as follows: A: 10 elements
B: 20 elements 
C: 30 elements
D: 40 elements

I want to remove $k < 100$ elements out of these $100$ elements randomly.
What algorithm will give me the random number of elements $k_A, k_B, k_C,$ and $k_D$ to remove from the respective buckets, such that 


*

*$k_A + k_B + k_C + k_D = k$, and 

*each element in the set has the same probability of being removed?

A: The criteria of "fairness" and exactly equal probability for all elements are not entirely compatible.
The expected value of the number of elements drawn from $A$ is $$k_A=k\cdot\frac{|A|}{100}$$ which is not in general an integer. So in order to take elements as evenly as possible, first take $\lfloor k_A\rfloor$ from $A$, $\lfloor k_B\rfloor$ from $B$, etc. Then you will have $r$ left over.
From this point there are many different options. For example, you can select $r$ of the non-empty buckets and take one from each. You could make a list of values of $\operatorname{frac}k_i$, sorted in descending order, then take one from the first $r$ sets on the list. You could randomly choose $r$ points on the interval $(0,\sum\operatorname{frac}k_i)$ and take elements from the sets corresponding to subintervals. All of these approaches have pitfalls and complications. It depends on what your priorities are, and what you consider fairest in this context.
