C#随机颜色和随机字母

//随机获取颜色

public System.Drawing.Color GetRandomColor()
{
Random RandomNum_First = new Random(Guid.NewGuid().GetHashCode());
Random RandomNum_Sencond = new Random(Guid.NewGuid().GetHashCode()); //为了在白色背景上显示,尽量生成深色
int int_Red = RandomNum_First.Next();
int int_Green = RandomNum_Sencond.Next();
int int_Blue = (int_Red + int_Green > ) ? : - int_Red - int_Green;
int_Blue = (int_Blue > ) ? : int_Blue; return System.Drawing.Color.FromArgb(int_Red, int_Green, int_Blue);
}

//随机字母

public static string GetPageName()
{
string strRand = String.Empty;
System.Random random = new Random(Guid.NewGuid().GetHashCode());
string str = "qwertyuiopasdfghjklmnbvcxz";
for (int i = ; i < ; i++)
{
strRand += str[random.Next(, )].ToString();
}
return strRand;
}
上一篇:Java程序员常犯的10个错误


下一篇:使用镜像源和trust-host解决:Could not fetch URL https://pypi.org/simple/xxxx/