1
Answer

Generating a Random Number

Aaron Svedin

Aaron Svedin

16y
2.3k
1

I am trying to generat a random number.

Code:

int pickRandomNumbers()

   {

      Random pickNum = new Random();

      int random1 = pickNum.Next(1, 20);

      return random1;

   }

 

void displayQuestion()

   {

      num1 = pickRandomNumbers();

      num2 = pickRandomNumbers();

      lblQuestion.Text = "How much is " + num1 + " times " + num2 + " ?";

   }

When I run the program, the question displays the same number, BUT when I Debug and follow the code, it gives me different numbers?

I understand that random uses the Time to help pick. Do i need to force it to wait a second, or what?

HELP?

Answers (1)