I want to make a function which takes lists as an input and outputs one element out of one of the list with uniform probability (if for example we have 2 lists, one with 7 and one with 3 elements, each element should have chance 1/10 to be picked) and removes that element from the list it was chosen from. This should work for 1,2 or 4 lists. I wouldn't mind creating 3 different functions for this. For 2 lists this would work:
randChoice[a_, b_] :=
Module[{ran = RandomInteger[{1, Length[a] + Length[b]}], pos, ret},
If[ran <= Length[a], ret = a[[ran]]; a = Delete[a, ran],
pos = ran - Length[a]; ret = b[[pos]]; b = Delete[b, pos]];
Return[ret];
];
SetAttributes[randChoice, HoldAll]
Example input:
a = {1, 2, 3, 4};
b = {1, 2, 3};
randChoice[a, b]
a
b
Is there a neater way to do this? It should be as fast as possible of course and should work for empty lists as well (though at least one list isn't empty).