'#'+Math.floor(Math.random()*16777215).toString(16);
var r = () => Math.random() * 256 >> 0;
var color = `rgb(${r()}, ${r()}, ${r()})`;
function getRandomRgb() {
var num = Math.round(0xffffff * Math.random());
var r = num >> 16;
var g = num >> 8 & 255;
var b = num & 255;
return 'rgb(' + r + ', ' + g + ', ' + b + ')';
}
for (var i = 0; i < 3; i++) {
console.log(getRandomRgb());
}
Run code snippetHide results
"#" + ((1<<24)*Math.random() | 0).toString(16));
var randomColor = "#000000".replace(/0/g,function(){return (~~(Math.random()*16)).toString(16);});