Skip to content

Instantly share code, notes, and snippets.

@evdokimovm
Last active August 15, 2021 02:16
Show Gist options
  • Save evdokimovm/c77bb2bd3cd6fc003d71b65cc3459542 to your computer and use it in GitHub Desktop.
Save evdokimovm/c77bb2bd3cd6fc003d71b65cc3459542 to your computer and use it in GitHub Desktop.
Get Random Color
function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
function getRandomColor() {
var r = Math.floor(Math.random() * 255);
var g = Math.floor(Math.random() * 255);
var b = Math.floor(Math.random() * 255);
var a = (Math.random() * 1).toFixed(3);
console.log("rgba(" + r + "," + g + "," + b + "," + a + ")");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment