private string GetColor()
{
Random tempR = new Random();
Random rR = new Random((int)DateTime.Now.Ticks);
System.Threading.Thread.Sleep(tempR.Next(50));
Random rG = new Random((int)DateTime.Now.Ticks);
System.Threading.Thread.Sleep(tempR.Next(50));
Random rB = new Random((int)DateTime.Now.Ticks);
string colorR = Convert.ToString(rR.Next(rB.Next()) % 16, 16);
string colorG = Convert.ToString(rG.Next(rR.Next()) % 16, 16);
string colorB = Convert.ToString(rB.Next(rR.Next()) % 16, 16);
if (colorR == "0")
{
colorR = "00";
}
if (colorG == "0")
{
colorG = "00";
}
if (colorB == "0")
{
colorB = "00";
}
return "#" + colorR + colorG + colorB;
}
C#生成随机颜色,返回16进制字符串
最新推荐文章于 2022-02-23 09:47:44 发布