Generate Random Color distinguishable to Humans

前端 未结 9 918
旧时难觅i
旧时难觅i 2020-12-12 14:11

I am trying to randomly generate a color in hex in javascript.

However the colors generated are almost indistinguishable from eachother.
Is there a way to improv

9条回答
  •  隐瞒了意图╮
    2020-12-12 14:51

    Try this:

    function getRandomColor() {
        var letters = '0123456789ABCDEF'.split('');
        var color = '#';
        for (var i = 0; i < 6; i++ ) {
            color += letters[Math.round(Math.random() * 15)];
        }
        return color;
    }
    

    See it in action: http://jsfiddle.net/3wjgG/1/

提交回复
热议问题