+ 1

Call a random method? C#

I'm making a choose your own adventure sorta game for the console on visual studio and I was wondering how I can execute a random method. Basically I have two methods FirstLevel and SecondLevel and after I press a key I want one of the two methods to be executed at random. This shouldn't be so hard to figure out I assume but either I'm suffering a major brainfart or I'm just stupid lol. Any help is appreciated.

16th Jan 2019, 1:03 PM
Liam McGuire
Liam McGuire - avatar
2 Réponses
+ 2
You can use the Random class and a condition: Random random = new Random() ; if (random.next(2) == 1) { Method(); } else { Method2(); }
16th Jan 2019, 1:21 PM
Eldar Bakerman
0
I cant believe it was that simple, thank you so much
16th Jan 2019, 1:29 PM
Liam McGuire
Liam McGuire - avatar