The obvious approach is simply to convert the identifier to color (for example, the bottom 8 bits are blue, the next 8 bits are green, the next 8 bits are red - leave 8 bits, but I'm sure you can understand it ;-)
Assuming this doesn't work (because you fall into a terrible color palette: Use an array (or hash table) to map identifiers to colors.
If you are concerned that there are too many identifiers, you can apply some hash to the identifier and use it when entering the "id to color" display. In this case, you are actually saying that one identifier always has one color, but one color can be used by many identifiers.
source share