0

This loop runs when the method is called and the input is defined on the amount a user inputs when prompted.

    string randomNumbers(int a)
    {
        var answer = "";

        for (int i = 0; i < a; i++)
        {
            var rand = new Random();
            var rnd1 = rand.Next(1, 15);
            var rnd2 = rand.Next(6, 15);
            var rnd3 = rand.Next(15);

            answer += String.Format($"{i} - Here are the random numbers: {rnd1}, {rnd2} & {rnd3}\n\n");
        }

        return answer;
    }

As expected when the loop runs and i = 0 a value is created and then when i = 1 it gets a new value.

However something weird happens with every consecutive runs after that - no matter what the number is after 1, the value does not change.

Why is this the case?

If the i = 0 and i = 1 values where the same I could think of reasons, but I am missing something here and I do not see what. Any help is always appreciated.

jwknz
  • 6,598
  • 16
  • 72
  • 115

0 Answers0