mercredi 2 septembre 2015

Two different random number generators giving the same answer?

    static void Main(string[] args)
    {

        //random number gen
        Console.WriteLine("Array Random Number:");
        randomGenA();
        Console.WriteLine("------------------");

        //LIST: random movie picker...
        Console.WriteLine("List Random Number:");
        randomGenB();
        Console.WriteLine("------------------");

        Console.ReadLine();
    }

    static void randomGenA()
    {
        Random randomA = new Random();
        int randomNumA = randomA.Next(51);

        Console.WriteLine(randomNumA);

    }
    static void randomGenB()
    {
        Random randomB = new Random();
        int randomNumB = randomB.Next(0,51);

        Console.WriteLine(randomNum);
    }
 }

I wanted them both to produce two different random numbers but instead I keep getting the same random number from both of them. Why does it do this?




Aucun commentaire:

Enregistrer un commentaire