Skip to content

Instantly share code, notes, and snippets.

@alexanderjeurissen
Created January 3, 2014 19:56
Show Gist options
  • Save alexanderjeurissen/8245379 to your computer and use it in GitHub Desktop.
Save alexanderjeurissen/8245379 to your computer and use it in GitHub Desktop.
public string pastelColorForString (string s) {
UInt32 hashCode = BitConverter.ToUInt32 (
new SHA1CryptoServiceProvider ().ComputeHash (
Encoding.UTF8.GetBytes (s)
),0
);
return "#" +
((((hashCode >> 24) & 0xFF)+255)/2).ToString ("X") +
((((hashCode >> 16) & 0xFF)+255)/2).ToString ("X") +
((((hashCode >> 08) & 0xFF)+255)/2).ToString ("X");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment