Random encounter not so random

You’re creating a new Random for each single value you need.

Try creating a unique Random object and calling the .Next() function multiple times.

public Color getRandomColor()
{
    Random rand = new Random();

    Color1 = rand.Next(rand.Next(0, 100), rand.Next(200, 255));
    Color2 = rand.Next(rand.Next(0, 100), rand.Next(200, 255));
    Color3 = rand.Next(rand.Next(0, 100), rand.Next(200, 255));
    Color color = Color.FromArgb(Color1, Color2, Color3);
    Console.WriteLine("R: " + Color1 + " G: " + Color2 + " B: " + Color3 + " = " + color.Name);
    return color;
}

Taken from MSDN documentation on Random object :

By default, the parameterless constructor of the Random class uses the system clock to generate its seed value, while its parameterized constructor can take an Int32 value based on the number of ticks in the current time. However, because the clock has finite resolution, using the parameterless constructor to create different Random objects in close succession creates random number generators that produce identical sequences of random numbers

Leave a Comment