문제

I stumbled over this blogpost by Brian Suda and quickly applied the "Dopplr’s coloring algorithm" to some examples, and that this works is not in question. What is, is why?

The process is as follows:

$hex_color = sub-string(md5($original_string), 0, 6)

Input some string (e.g. city names as with dopplr's original usage), make a md5-hash of this, and use the first 6 digits from the hash. Prepend this with a "#" and a string is transformed into a color fit for use in CSS-documents etc.

How is it that the six first digits of a md5-hash always matches a color in the hexadecimal representation?

도움이 되었습니까?

해결책

MD5 always outputs hex. Colors can be represented as a 6-character hex string in css. So, the MD5 hash is just producing a semi-random hex string.

And any hex string (that is 6 characters long and begins with a #) is valid to define a color.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top