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
I tried all the solutions others provided but found that similar strings (string1 vs string2) produce colors that are too similar for my liking. Therefore, I built my own influenced by the input and ideas of others.
This one will compute the MD5 checksum of the string, and take the first 6 hex digits to define the RGB 24-bit code.
The MD5 functionality is an open-source JQuery plug in. The JS function goes as follows:
function getRGB(str) {
return '#' + $.md5(str).substring(0, 6);
}
A link to this working example is on jsFiddle. Just input a string into the input field and press enter, and do so over and over again to compare your findings.