So, I am trying to make a hash function that, given a string will return a unique color. Not a random color, but the same color everytime. I am just hoping to make it hash oddly enough that the colors will be varied. I am using it in a bar graph to color the different bars. With what I have now I am getting shades of red only. Anybody got any ideas to make this hash better?
VB Code:
Private Function ColorHash(ByVal strHashThis As String) As System.Drawing.Color Dim x, y, z As Integer '122 is ascii value of 'Z' '57 is number of characters from 'a' to 'Z' x = ((122 - Asc(strHashThis.Chars(0))) * 5) + Asc(strHashThis.Chars(strHashThis.Length - 1)) x = ((122 - Asc(strHashThis.Chars(strHashThis.Length - 1))) * 5) + Asc(strHashThis.Chars(0)) z = (strHashThis.Length Mod 57) * 5 Return Color.FromArgb(x Mod 255, y Mod 255, z Mod 255) End Function




Reply With Quote