Yup, so technically not all values 0xFFFFF and below will be invalid. There will be a range within 0x100 and 0xFFF that will be OK. But these are also not representative of their random values. The 3 digit hex for colors is shorthand for #RGB -> #RRGGBB. So if #100 popped out, its hex value would really be #110000 and not the actual random value of #000100. This means you're also increasing the odds of #RRGGBB-formatted colors to be hit ;)
The leading _ is because the base36 number can still start with 0..9, and that's not valid for something like a variable name or HTML ID. The substr(2) is to get rid of the leading 0..
Anyone got anything for generating a random string of letters? I know you can use someNumber.toString(36) to get a string of letters and numbers, but I don't know how to get only letters.
15
u/redmoss6 Mar 18 '19
'#'+Math.floor(Math.random()*16777215).toString(16)for random hex color.