Generating Unique Colors I just wrote a small class that generates perfectly unique colors(or that is the plan anyway). I found the original index shifting snippet online, and was just wondering if it could be improved in anyway, or if any problems could arise from using it.

Here is the class which is used to create the unique colors.

public class UniqueColorGenerator
    {
        private int _colorIndex;
        public UniqueColorGenerator()
        {

        }

        public Color Next()
        {
            _colorIndex++;
            byte red = ( byte )( _colorIndex &amp; 0x000000FF );
            byte green = ( byte )( ( _colorIndex &amp; 0x0000FF00 ) &gt;&gt; 08 );
            byte blue = ( byte )( ( _colorIndex &amp; 0x00FF0000 ) &gt;&gt; 16 );
            return Color.FromArgb( red , green , blue );
        }
    }


I am using this for "geometry picking" in OpenGL. It works beautifully, too. Here is a picture of 16,384 quads with their own unique color... or I guess I should say "unique shade of red and black".



When I first ran it, I could swear that there were obvious duplicates, but there aren't. Not only did the picking work flawlessly, but I also ran through the Colors and didn't get a single collision. Though I am still wondering if any problems could arise from how the generator is currently built—besides hitting integer max, which will also never happen.

Also, how can I randomize the colors more, so instead of getting different shades of red, I could receive more colors along the spectrum?
You don't need the constructor, as it's empty.

You're taking red as the low bits and blue as the high bits, which is backwards. 

You appear to be using System.Drawing and not System.Windows.Media, judging by the overloads. If so, there is an overload that takes an int:

public class UniqueColorGenerator
{
    private int _colorIndex;

    public Color Next()
    {
        return Color.FromArgb(++_colorIndex);
    }
}


You also wouldn't need to use &amp;, as casting to a byte will cut off the upper bits. 

return Color.FromArgb(
    (byte)(_colorIndex &gt;&gt; 24), 
    (byte)(_colorIndex &gt;&gt; 16), 
    (byte)(_colorIndex &gt;&gt; 8), 
    (byte)_colorIndex);