Converting a random string into a hex colour
javascript
Solution
var color_codes = {};
function stringToColorCode(str) {
return (str in color_codes) ? color_codes[str] : (color_codes[str] = '#'+ ('000000' + (Math.random()*0xFFFFFF<<0).toString(16)).slice(-6));
}
Problem
I have a table of action logs in my application. I want to assign rows a random colour based on the sessionID of that entry to help see patterns/grouped actions. I have this so far: ``` console.log(stringToColorCode('mj3bPTCbIAVoNr93me1I')); function stringToColorCode(str) { return '#'+ ('000000' + (Math.random()*0xFFFFFF<<0).toString(16)).slice(-6); } ``` However I need to replace Math.random() with my string-integer, are there any techniques for converting a string to a random number that remains consistent with the random string?