JSFiddle - React, Tailwind, and code Playground
JavaScript
var colors = [];
function getRandUniqColor()
{
var r = getRGBString(),
g = getRGBString(),
b = getRGBString(),
rgb = r + g + b;
if ( colors.indexOf(rgb) == -1 )
{
colors.push(rgb);
return {
r: r,
g: g,
b: b
}
}
else
{
return getRandUniqColor()
}
}
function getRGBString()
{
var str = Math.floor(Math.random()*255).toString();
while (str.length < 3)
{
str = '0' + str;
}
return str;
}
// Just to generate the samples
var i = 0, rgb, html = '';
while (i < 40)
{
rgb = getRandUniqColor();
rgb = "rgb(" + +rgb.r + "," + +rgb.g + "," + +rgb.b + ")";
html += '<span style="background:' + rgb + '">' + rgb + '</span><br />';
i++;
}
$('body').append(html);