I think it's not "randomly" but better treat it like being random.
I suppose e.g. every new connection attempt increases the cid value (got a LOT failed reconnection attempts these days, and one recent connection had a cid value > 1000).