How can I generate a random human-readable colour from a seed? C#

Posted by SLC on Stack Overflow See other posts from Stack Overflow or by SLC
Published on 2010-04-26T06:58:58Z Indexed on 2010/04/26 7:03 UTC
Read the original article Hit count: 202

Filed under:
|
|

Got a logfile, and it has all kinds of text in it. Currently it is just displayed as one colour, and each entry says something like:

Log from section 1: Some text here 
Log from section 125: Some text here 
Log from section 17: Some text here 
Log from section 1: Some text here 
Log from section 125: Some text here 
Log from section 1: Some text here 
Log from section 17: Some text here

Now the logfile is displayed in real time, and it would be nice to make the rows with the same section number the same colour. However there could be potentially quite a large range of numbers.

What I want to do is create a method that will take a number, and randomly generate a unique colour. The colour must be readable against a black background though, so #000000 is no good, nor is #101010 or anything too dark to read.

Ideally two similar numbers will not produce the same colour because in the above examples, the numbers 1 and 17 might be too similar, and some numbers might be in the 10,000 range.

Any ideas on this?

© Stack Overflow or respective owner

Related posts about colors

Related posts about c#