Skip to content

Instantly share code, notes, and snippets.

@z-------------
Created April 7, 2014 03:07
Show Gist options
  • Save z-------------/10014287 to your computer and use it in GitHub Desktop.
Save z-------------/10014287 to your computer and use it in GitHub Desktop.
Returns a random RGB color
var rndRGB = function(type){
var r = Math.round(Math.random()*255);
var g = Math.round(Math.random()*255);
var b = Math.round(Math.random()*255);
switch (type) {
case "array":
return [r,g,b]; break;
case "formatted":
return "rgb("+r+","+g+","+b+")"; break;
default:
return r+","+g+","+b; break;
}
}
// rndRGB() --> "234,12,98"
// rndRGB("array") --> [234,12,98]
// rndRGB("formatted") --> "rgb(234,12,98)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment