random string to css color
2013 by @TimPietrusky
Fork me on GitHub
How does this work?
- Change each non-hex character to a 0.
- Add 0's to the string until its length is a multiple of 3.
- Divide string into 3 equal parts.
- While the length of the sub-strings is greater than 2, and all three of the sub-strings begin with a 0, remove the leading 0s from each string.
- If the length of the sub-strings is still greater than 2, then truncate each substring to 2 characters.