I have various objects in my database identified by unique System.Guid's. When I display them, I would like each of them to have a unique color based on their guid.
So I want something like this:
public Color ColorFromGuid(Guid guid) { /* ?? */ }
Where
ColorFromGuid(databaseObject1.Guid) == ColorFromGuid(databaseObject1.Guid)
ColorFromGuid(databaseObject2.Guid) == ColorFromGuid(databaseObject2.Guid)
ColorFromGuid(databaseObject1.Guid) != ColorFromGuid(databaseObject2.Guid)
What would be the best way to do this?
EDIT Obviously there are WAY more unique guids than colors, so there’s no way that every guid will have it’s own unique color. I’m just looking for a good variety.
You could do:
If you need an opaque color, use the overload of
Color.FromArgbthat lets you specify the alpha. If you want similar GUIDs to generate very different colors, you can do a different sort of hash on the Guid, e.g. an MD5 hash, and get the number to generate your color from that.