Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How do i write a script which generates a random rgb color number.

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 < 10; i++) {
  console.log(getRandomRgb());
}
 Run code snippet
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #write #script #generates #random #rgb #color
ADD COMMENT
Topic
Name
3+8 =