How do I generate random dark colors in C#?

One way to do this is to generate colours in the HSV/HSL colour-space, and then convert to RGB (the Wikipedia article tells you how to do that).

The advantage of HSV is that one of the components (V) corresponds to "brightness". So if you generate H, S and V independently and randomly, but restrict V to low values, then you will get dark colours.


An quite simple way to get rid of the "upper half" of brightes colors is to mask the result via

random.Next(0x1000000) & 0x7F7F7F

Tags:

C#

Colors