How to make the computer choose between two characters

0

Well, I'm not sure if this is the case, but I'm not sure how to do this. class random, but I found some problems, as I'm working with string.

    
asked by anonymous 01.06.2017 / 23:28

1 answer

4

Use Random, and test whether it is even or odd. And assign a corresponding Character, Ex: "X" when even, and "O" when odd.

Random from 0 to 99, 100 possibilities, probability equal.

Random r = new Random();
string Jogo =  r.Next(0, 99) % 2 ==0 ? "X" : "O";

Surely you should only do this on the first move.

    
01.06.2017 / 23:38