Answers for "random color javascript from string"

13

javascript random color generator

function generateRandomColor() {
  var letters = '0123456789ABCDEF';
  var color = '#';
  for (var i = 0; i < 6; i++) {
    color += letters[Math.floor(Math.random() * 16)];
  }
  return color;
}

var randomColor=generateRandomColor();//"#F10531"
Posted by: Guest on August-05-2019
0

js random color

//1.
var color = '#'+Math.floor(Math.random()*256).toString(10);
//2.
var color = '#'+Math.floor(Math.random()*0xffffff).toString(16);
//3.
function rgb(){// rgb color random
		var r = Math.floor(Math.random()*256);
		var g = Math.floor(Math.random()*256);
		var b = Math.floor(Math.random()*256);
		var rgb = 'rgb('+r+','+g+','+b+')';
		return rgb;
	}
//4.
function color16(){// hexadecimal color random
  var r = Math.floor(Math.random()*256);
  var g = Math.floor(Math.random()*256);
  var b = Math.floor(Math.random()*256);
  var color = '#'+r.toString(16)+g.toString(16)+b.toString(16);
  return color;
}
Posted by: Guest on June-22-2021

Code answers related to "random color javascript from string"

Code answers related to "Javascript"

Browse Popular Code Answers by Language