+ 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.
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();
}
0
I cant believe it was that simple, thank you so much