import bpy
from random import random
for o in bpy.data.objects:
if(o.type == 'MESH'):
if((o.color[:4] == (1,1,1,1)) or (o.color[:4] == (0,0,0,0))):
o.color = (random(),random(),random(),1)
if(bpy.context.scene.render.engine == 'BLENDER_RENDER'):
o.material_slots.data.active_material.use_object_color = True
if(bpy.context.scene.render.engine == 'CYCLES'):
o.material_slots.data.active_material_index = 0
o.material_slots.data.active_material.diffuse_color = o.color[:3]
What it does is set a random color for the object, and then make the first material use it. It generates a new color if the object color is default white with alpha 1, or black with alpha 0, where latter comes from resetting the color.