How do I generate random dark colors in C#?

前端 未结 3 1088
眼角桃花
眼角桃花 2021-01-02 09:07

I generate a random color this way:

 var random = new Random();
 var color = String.Format(\"#{0:X6}\", random.Next(0x1000000)); 

How can I

3条回答
  •  一个人的身影
    2021-01-02 09:33

    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.

提交回复
热议问题