lundi 29 juin 2020

Random number generation giving same numbers few times consecutively

I want to create random numbers multiple times. In the snippet below, i try to generate 100 numbers between 0 and 5 from the same random variable. Still , i am getting the same numbers consecutively . I just want that my next number should be different from prev one generated.

            Random random = new Random();

            for(int i=0;i<100;i++)
            {
                int num   = random.Next(5);
                Console.WriteLine(num);
            }

Picture of how the numbers were showing up .

Attached the picture of how the numbers were showing up !




Aucun commentaire:

Enregistrer un commentaire