'#'+Math.floor(Math.random()*16777215).toString(16);
const randomHex = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0")}`;
console.log(randomHex());
// Result: #92b008
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);});