0

Hello Im trying to generate many consecutive random number with a for but i always get the same number. The problem is that I need the for. This is my methode.

public static int roll(int numberRoll, int maxNumber)
    {
        Random random1 = new Random();
        int someRoll = 0;

            for (int i = 0; i < numberRoll; ++i )
        {
            someRoll += random1.Next(1,maxNumber);
        }
        return someRoll;
Thombien
  • 1
  • 1
  • How i can put it outside of the methode beacause it become an object ? – Thombien Jan 21 '17 at 01:27
  • @Thombien you do it by passing in a `Random` in to the function in the place that calls this function it likely too has a loop, you need to create the new Random outside of that loop. This is safer than using a static Random because Random is not thread safe. – Scott Chamberlain Jan 21 '17 at 01:31
  • ok thx I was missing the static before – Thombien Jan 21 '17 at 01:33

0 Answers0