TIC TAC TOE/ random number generator

Sony Vaio vgn-fj270p notebook
June 7, 2010 at 22:33:33
Specs: Windows XP
I have a tic tac toe program that i want it to
generate random numbers for the X and
O...this is what i have


public void actionPerformed(ActionEvent a) {
count++;
if(count == 1 || count == 3 || count == 5 ||
count == 7 || count == 9){
letter = "X";
} else if(count == 2 || count == 4 ||
count == 6 || count == 8 || count == 10){
letter = "O";
}

but in place of this i wanted so it will randomly
pick X and O's not in order of the clicks. I hope
i explained it well


See More: TIC TAC TOE/ random number generator

Report •

#1
June 8, 2010 at 06:49:33
I don't know Java, but I'd assume it'd look something like this:
Random rand = new Random()
letter = (rand.nextInt() & 1 == 1) ? 'X' : 'O';


Report •
Related Solutions


Ask Question