hi all. i have a two-dimensional array of System.Drawing.Color that I wish to populate with random colors. I have created a class called Utilities that I want to place a RandomColor() method so that various classes within my program can use it...
so this is what the utilities class looks like so far:
class Utilities
{
public static Color RandomColor()
{
Color color = new Color();
Random rand = new Random();
switch (rand.Next(1, 8))
{
case 1:
color = Color.Blue;
break;
case 2:
color = Color.Red;
break;
case 3:
color = Color.Green;
break;
case 4:
color = Color.Yellow;
break;
case 5:
color = Color.Orange;
break;
case 6:
color = Color.Violet;
break;
case 7:
color = Color.White;
break;
case 8:
color = Color.Black;
break;
}
return color;
}
}
and here is the loop where i populate the grid with colors:
public void Update()
{
for (int i = 0; i < Width; i++)
for (int j = 0; j < Height; j++)
_grid[i, j] = Utilities.RandomColor();
}
but the grid is being filled completely with one color. why should this happen? each call to the RandomColor method initializes a new Random number, so why are they all filling with the same color? when I call Update() later in the program, the grid once again fills with the same color, except this time a different one (so it's working but not the way I want it to!)
can anyone tell me what I am doing wrong?
thank you!
-SelArom