I need a function to generate a CSS color based on a string with a range of min: #000000 and max: #FFFFFF. If the length or any of the characters in the input string changes, the function should return a different color (but it must always return the same color on the same string input).
For Example:
f("Reddit") ==>#FF0000
f("Smith") ==>#FFC0CB
f("Smixh")==>#F008FF
f("Smith") ==>#FFC0CB
f("foo")==>#FF00FF
f("Reddit") ==>#FF0000
And so on. Any idea how to do that?
I’d hash the string and use the first six characters of the hex checksum as your hex color code:
Demo: http://jsfiddle.net/4PMnA/48/