I wrote this C# code snippet here. The idea is to generate a random .NET Color in RGB, while keeping alpha at 255 (i.e. full)
My question is does this function have the potential to hit every colour in RGB space? I thought I was but now I’m second guessing myself. Alternatively is there a better way to do this?
Thanks.
const int COLORSPACE = 0xFF * 0xFF * 0xFF;
const int ALPHA = 0xFF << 24;
Random _rand = new Random();
Color RandomColor
{
get
{
return Color.FromArgb(_rand.Next(COLORSPACE) + ALPHA);
}
}
No. The (exclusive!) upper bound should be 0x1000000, not 0xFF * 0xFF * 0xFF.
0xFF * 0xFF * 0xFF is only 0xFD02FF, so you’re missing that colour and all higher colours.