A friend just loosely wondered how the colours of nicknames in Hexchat are determined. For the uninitiated, Hexchat is an IRC client which (at least, by default) colours various users nicknames randomly (‘tobias’ might be green, but ‘daniel’ might be red) in a consistent manner (e.g. if the nick ‘tobias’ is green right now, it’ll be green for all time)
Given I’ve wondered this myself in the past, I decided to look into it (and it turned out to be entirely straightforward)
This takes a user’s name and finds the sum of every character’s ASCII value, returning a colour code based upon the remainder of the sum when divided by how many colour codes there are.
I personally had expected a seeded random number, where the user’s name is used as a seed for some more sophisticated random function (though I was evidently wrong). This implementation is more efficient, though anagrams of a user’s name will always be the same colour.
This might be a problem if you’re talking to two people named Tobias and Toibas, both will be the same colour. Not only will it be confusing, it may be easier for a maliciously inclined user to impersonate some other user (if you associate a person and the colour of their name).
That said, there are only a handful of different colours which usernames can be given. If a seeded random approach was used (as I would have done), it would remain relatively simple to find another similar looking name with the same colour (unless the name was relatively short). Thus the chosen approach doesn’t particularly matter in this regard, though the implemented approach remains faster.