Arrays and random numbers: count the times an integer is randomly generated
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1421802/count-frequency-in-a-randomly-generated-list-of-numbers">Count Frequency in a Randomly Generated List of Numbers</a>  </p>
</blockquote>



<p>I am currently working with arrays and random numbers. I have a created a form that will let me generate random numbers from 1 - 20 with a textbox1 to choose the quantity of numbers displayed. I am displaying the results inside a multiline textbox2. I have been able to calculate the sum and average of the set of numbers generated.</p>

<p>My second step: </p>

<p>Is there away to tally or mark the times a number is generated and display it in the multiline textbox(last picture)? Would I need to create an array and make it full of zero?</p>

<pre><code>private void button1_Click(object sender, EventArgs e)
{
    int n = Convert.ToInt32(textBox1.Text);
    int[] y = new int[n];
    double sum = 0;

    for (int i = 0; i &lt; n; i++)
    {
        int x = 1 + r.Next(20);
        y[i] = x;
        sum += x;

        if (n &lt; 101)
            textBox2.AppendText(x + " ");
    }

    double avg = sum / n;
    textBox2.AppendText(Environment.NewLine + sum + " " + avg + Environment.NewLine);

    double vsum = 0;

    for (int i = 0; i &lt; n; i++)
        vsum += (y[i] - avg) * (y[i] - avg);
}     
</code></pre>

<p><strong>Form.cs</strong></p>

<p><img src="http://i.stack.imgur.com/RtXyR.png" alt="enter image description here"></p>

<p><strong>Count the times an integer is randomly selected</strong></p>

<p><img src="http://i.stack.imgur.com/LhzOH.png" alt="enter image description here"></p>
