Skip to content

Instantly share code, notes, and snippets.

@dchapkine
Last active December 25, 2015 03:28
Show Gist options
  • Save dchapkine/6909493 to your computer and use it in GitHub Desktop.
Save dchapkine/6909493 to your computer and use it in GitHub Desktop.
getRandomColorString & getRandomColor
var getRandomColor = function() {
return {
r: Math.floor(Math.random()*255),
g: Math.floor(Math.random()*255),
b: Math.floor(Math.random()*255),
a: parseFloat(Math.random().toFixed(2))
}
};
var getRandomColorString = function(alpha) {
alpha = !!alpha || false;
var c = {
r: Math.floor(Math.random()*255),
g: Math.floor(Math.random()*255),
b: Math.floor(Math.random()*255),
a: parseFloat(Math.random().toFixed(2))
};
return "rgb"+(alpha?"a":"")+"("+c.r+", "+c.g+", "+c.b+(alpha?", "+c.a:"")+")";
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment