Is there a best practice on how to hash an arbitrary string into a RGB color value? Or to be more general: to 3 bytes.
You\'re asking: When will I ever need this? It doe
As an example, this is how Java calculates the hashcode of a string (line 1494 and following). It returns an int
. You can then calculate the modulo of that int
with 16,777,216 (2^24 = 3 bytes) to get an "RGB-compatible" number.
It is a deterministic calculation so the same word(s) will always have the same colour. The likelihood of hash collision (2 strings having the same colour) is small. Not sure about the colour distribution, but probably fairly random.