Using Random object to generate colors
<p>I've got a vey simple form with a grid of 16 labels, each of which I wish to set the Background color at random from 12 colors I have chosen.</p>

<p>Here is my code:</p>

<pre><code>private void btnRandom_Click(object sender, EventArgs e)
    {
        txtA1.BackColor = RandomColor();
        txtA2.BackColor = RandomColor();
        txtA3.BackColor = RandomColor();
        txtA4.BackColor = RandomColor();
        txtB1.BackColor = RandomColor();
        txtB2.BackColor = RandomColor();
        txtB3.BackColor = RandomColor();
        txtB4.BackColor = RandomColor();
        txtC1.BackColor = RandomColor();
        txtC2.BackColor = RandomColor();
        txtC3.BackColor = RandomColor();
        txtC4.BackColor = RandomColor();
        txtD1.BackColor = RandomColor();
        txtD2.BackColor = RandomColor();
        txtD3.BackColor = RandomColor();
        txtD4.BackColor = RandomColor();
    }

    private Color RandomColor()
    {            
        Random rand = new Random();
        int r = rand.Next(1, 12);
        switch (r)
        {
            case 1:
                return Color.FromKnownColor(KnownColor.DodgerBlue);
            case 2:
                return Color.FromKnownColor(KnownColor.MediumAquamarine);
            case 3:
                return Color.FromKnownColor(KnownColor.Teal);
            case 4:
                return Color.FromKnownColor(KnownColor.OrangeRed);
            case 5:
                return Color.FromKnownColor(KnownColor.LightCoral);
            case 6:
                return Color.FromKnownColor(KnownColor.Red);
            case 7:
                return Color.FromKnownColor(KnownColor.MediumOrchid);
            case 8:
                return Color.FromKnownColor(KnownColor.MediumPurple);
            case 9:
                return Color.FromKnownColor(KnownColor.DarkOrchid);
            case 10:
                return Color.FromKnownColor(KnownColor.Lime);
            case 11:
                return Color.FromKnownColor(KnownColor.PaleGreen);
            case 12:
                return Color.FromKnownColor(KnownColor.SeaGreen);
            default:
                return Color.FromKnownColor(KnownColor.White);
        }
    }
</code></pre>

<p>But what is happening is that ALL 16 labels are assigned the same backcolor, rather than each being randomized individually.</p>

<p>What am I doing wrong?</p>
