davidmerfield / randomColor

A tiny script for generating attractive colors
Creative Commons Zero v1.0 Universal
6.09k stars 401 forks source link

"Truly Random" isn't actually random? #144

Open bryc opened 3 years ago

bryc commented 3 years ago
randomColor({hue: 'random',luminosity: 'random',count: 54});

More of a pet peeve than an severe issue: On the demo page, you have the above code for Truly Random colors, but it produces dark colors more often than not, so it appears biased and/or constrained to certain saturations and luminosities (which means its not truly random).

Comparison of randomColor on the left, to fully random RGB values (on the right).

image

davidmerfield commented 3 years ago

Hmm, good catch, I had wondered that myself. I'm not sure why this is happening, it should picking between 0 and 100 for both Saturation and Brightness in the HSB color space. Will investigate.

Code for Brightness: https://github.com/davidmerfield/randomColor/blob/master/randomColor.js#L172-L174 Code for Saturation: https://github.com/davidmerfield/randomColor/blob/master/randomColor.js#L129-L131