random numbers on Page_Load
<p>I am creating a simple game where the computer generates random numbers and adds them up. The rule is that while the addition of both random numbers is &lt; 17, generate another random number and add it to the previously generated. The computer also generates a random number for the user. However, the user decides whether he wants to generate more or not. In case he wants, the newly generated number is added to the previous ones. </p>

<p>The problem I am facing is that, the computer function of generating his random numbers is in the Page_Load event. This is leading to a problem; meaning that when the user has his random number displayed, lets say he decides to generate another one. In a Button_Click event, the user presses "Generate" button and has his newly random number. The problem in that is whenever the button is pressed, the page refreshes and the computer random numbers are changed since the method is in the page_load event. </p>

<p><strong>How can I make the computer generate a random number, store it, without being effected by other events on the page. Also, how can I add the newly generated random number for the user to the previously generated ones?</strong> </p>

<p>This is the code:</p>

<pre><code>int computer_first_number;
int computer_second_number;
int extra_number;
int computer_total;
int user_number1;
int user_number2;
int user_total;

private int randomNumber(int min, int max)
{
Random random = new Random(BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0));
return random.Next(min, max);
}

protected void Page_Load(object sender, EventArgs e)
{
       computer_first_number = randomNumber(1, 10);
       computer_second_number = randomNumber(1, 10);
       user_number1 = randomNumber(1, 10);
       computer_total = computer_first_number + computer_second_number;

       while (computer_total &lt; 17)
       {
          try
          {
              extra_number = randomNumber(1, 10);
              computer_total = computer_first_number + computer_second_number + extra_number;
          }
          catch (Exception ex)
          {
              Console.Write(ex);
          }
       }
}

protected void Button1_Click1(object sender, EventArgs e)
{
       user_number2 = randomNumber(1, 10);
       user_total = user_number1 + user_number2;
       Label4.Text = Convert.ToString(user_total);
 }
</code></pre>
