Alex Rivera | Logout

How do I generate random dark colors in C#?

Asked 2011-06-18T13:03:19.207
10

I generate a random color this way:

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

How can I exclude colors brighter than a certain value?

Edit
Report

1 Answer

12

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

random.Next(0x1000000) & 0x7F7F7F
answered 2011-06-18T13:14:29.107

Your Answer