Generate random IDs and avoid collisions.