samedi 30 décembre 2017

Use ONE random data type but generate different results? Please help [NEW TO CODING]

This is my first time using C# and our teacher required us to create a turn-based game as our finals exam. She only taught us basic codes so I'm only going on what I've learned from the Internet and I need help.

Below is the code I used to declare the variables:

        Random x= new Random();
        int xval;
        string xresult;

        xval = x.Next(4);
        string[] xlist = {
            "ZERO",
            "ONE",
            "TWO",
            "THREE",
        };
        xresult = xlist[xval];

My problem is that the result is the same for all the times I used it. I want it to change or reset each time. If you can help, it'd really be appreciated. Thanks.




Aucun commentaire:

Enregistrer un commentaire