The solution I ended up using is to give each object a random black and white object color with a simple script, and then to render those colors out as a separate render-layer to be used as a mix factor.
#set sel to selected objects
sel = bpy.context.selected_objects
#for each object in the selected group, assign a random object color
for ob in sel:
n = random.random()
ob.color = (n, n, n, 1) #this sets all color channels to "n" resulting in b/w color
This results in each object having a random (not necessarily unique) object color.
I then made a new shadeless material that derived the color from the object color:
And made a new render-layer with it as the override material:
This resulted in a perfect mask that I could use to mix elements and colors in the compositor with: