Hi, I have made a sudoku game where the computer plays against the user(human) and need help implementing one part of it. I have tried everything!!
So I've done Mode 1 where the user selects moves for both the human and the computer using StdIn, but now I have to do mode 0 where the computer does a random move.

Here is my code so far:

public class Twoduko {
static int Board[][];

public static void main(String[] args) {
StdOut.print("Enter the height of the grid:");
int H = StdIn.readInt();
StdOut.print("Enter the width of the grid:");
int W = StdIn.readInt();
StdOut.print("Enter the mode:");
int M = StdIn.readInt();

generateBoard(H, W);
drawBoard(H, W);
playGameModeZero(H, W, M);
playGameModeOne(H, W, M);
playGameModeTwo(H, W, M);
}

public static void generateBoard(int H, int W) {

int tempBoard[][] = new int[H * H][W * W];

for (int i = 0; i < H * H; i++) {
for (int j = 0; j < W * W; j++) {

tempBoard[i][j] = 0;
}
}
Board = tempBoard;
}

public static void drawBoard(int H, int W) {
if (W == 2) {
System.out.println("+---+---++---+---+");
} else if (W == 3) {
System.out.println("+---+---+---++---+---+---++---+---+---+");
} else if (W == 4) {
System.out.println("+---+---+---+---++---+---+---+---++---+---+---+---++---+---+---+---+");
} else if (W == 5) {
System.out.println(
"+---+---+---+---+---++---+---+---+---+---++---+---+---+---+---++---+---+---+---+---++---+---+---+---+---+");
}

for (int i = 0; i < H * H; i++) {

for (int j = 0; j < W * W; j++) {

if (W == 2 && j == 2) {
System.out.print("||");
} else if (W == 3 && j == 3) {
System.out.print("||");
} else if (W == 3 && j == 6) {
System.out.print("||");
} else if (W == 4 && j == 4) {
System.out.print("||");
} else if (W == 4 && j == 8) {
System.out.print("||");
} else if (W == 4 && j == 12) {
System.out.print("||");
} else if (W == 5 && j == 5) {
System.out.print("||");
} else if (W == 5 && j == 10) {
System.out.print("||");
} else if (W == 5 && j == 15) {
System.out.print("||");
} else if (W == 5 && j == 20) {
System.out.print("||");
} else {
System.out.print("|");
}
System.out.print(Board[i][j] + " ");
}
System.out.print("" + "|");
System.out.println("");

if (W == 2 && H == 2) {
if (i == 1)
System.out.println("+===+===++===+===+");
else
System.out.println("+---+---++---+---+");
}
if (W == 3 && H == 3) {
if (i == 2)
System.out.println("+===+===+===++===+===+===++=== +===+===+");
else if (i == 5)
System.out.println("+===+===+===++===+===+===++=== +===+===+");
else
System.out.println("+---+---+---++---+---+---++---+---+---+");
}
if (W == 3 && H == 2) {
if (i == 1)
System.out.println("+===+===+===++===+===+===++=== +===+===+");
else
System.out.println("+---+---+---++---+---+---++---+---+---+");
}
if (W == 4 && H == 4) {
if (i == 3)
System.out.println("+===+===+===+===++===+===+===+ ===++===+===+===+===++===+===+===+===+");
else if (i == 7)
System.out.println("+===+===+===+===++===+===+===+ ===++===+===+===+===++===+===+===+===+");
else if (i == 11)
System.out.println("+===+===+===+===++===+===+===+ ===++===+===+===+===++===+===+===+===+");
else
System.out.println("+---+---+---+---++---+---+---+---++---+---+---+---++---+---+---+---+");
}
if (W == 4 && H == 2) {
if (i == 1)
System.out.println("+===+===+===+===++===+===+===+ ===++===+===+===+===++===+===+===+===+");
else
System.out.println("+---+---+---+---++---+---+---+---++---+---+---+---++---+---+---+---+");
}
if (W == 4 && H == 3) {
if (i == 2)
System.out.println("+===+===+===+===++===+===+===+ ===++===+===+===+===++===+===+===+===+");
else if (i == 5)
System.out.println("+===+===+===+===++===+===+===+ ===++===+===+===+===++===+===+===+===+");
else
System.out.println("+---+---+---+---++---+---+---+---++---+---+---+---++---+---+---+---+");
}
if (W == 5 && H == 2) {
if (i == 1)
System.out.println(
"+===+===+===+===+===++===+===+===+===+===++===+== =+===+===+===++===+===+===+===+===++===+===+===+== =+===+");
else
System.out.println(
"+---+---+---+---+---++---+---+---+---+---++---+---+---+---+---++---+---+---+---+---++---+---+---+---+---+");
}
}
}

public static void playGameModeZero(int H, int W, int M) {
if (M == 0) {
boolean play = true;
boolean humanTurn = false;
boolean computerTurn = false;
int turn = 0;
if (turn % 2 == 0) {
System.out.println("Computer's turn");
}
if (turn % 2 == 0) {
computerTurn = true && humanTurn == false;
}
if (turn % 2 != 0) {
System.out.println("Human's turn");
}
if (turn % 2 != 0) {
humanTurn = true && computerTurn == false;
}
turn++;
while (play) {

if (humanTurn) {
int row = 0;
int column = 0;
int entry = 0;
StdOut.print("Enter row:");
row = StdIn.readInt();
StdOut.print("Enter column:");
column = StdIn.readInt();
StdOut.print("Enter your entry value:");
entry = StdIn.readInt();

if (entry <= 0 || entry >= (W * W + 1)) {
play = false;
System.out.println("Illegal move.");
}

if (row > W * W || column > H * H) {
play = false;
System.out.println("Illegal move. ");
}

for (int i = 0; i < H * H - 1; i++) {
if (Board[i][column] == entry) { // check row
play = false;
System.out.println("Illegal move.");
}
}

for (int j = 0; j < W * W; j++) { // check column
if (Board[row][j] == entry) {
play = false;
System.out.println("Illegal move.");
}
}
int subRow = 0;
int subCol = 0;
subRow = row / H;
subCol = column / W;

for (int i = 0; i < H; i++) { // check subgrid
for (int j = 0; j < W; j++) {
if (Board[i + H * subRow][j + W * subCol] == entry) {
play = false;
System.out.println("Illegal move.");
}
}
}
}
if (computerTurn) {
Board[(int) Math.random() * (W * W)][(int) Math.random() * (H * H)] = (int) (Math.random() * H * W)
+ 1;
}
}
}

}

public static void playGameModeOne(int W, int H, int M) {
if (M == 1) {
boolean play = true;
boolean humanTurn = false;
boolean computerTurn = false;
int turn = 0;
if (turn % 2 == 0) {
System.out.println("Computer's turn");
}
if (turn % 2 == 0) {
computerTurn = true && humanTurn == false;
}
if (turn % 2 != 0) {
System.out.println("Human's turn");
}
if (turn % 2 != 0) {
humanTurn = true && computerTurn == false;
}
turn++;

while (play) {
int row = 0;
int column = 0;
int entry = 0;
StdOut.print("Enter row:");
row = StdIn.readInt();
StdOut.print("Enter column:");
column = StdIn.readInt();
StdOut.print("Enter your entry value:");
entry = StdIn.readInt();

if (entry <= 0 || entry >= (W * W + 1)) {
play = false;
System.out.println("Illegal move.");
}

if (row > W * W || column > H * H) {
play = false;
System.out.println("Illegal move. ");
}

for (int i = 0; i < H * H - 1; i++) {
if (Board[i][column] == entry) { // check row
play = false;
System.out.println("Illegal move.");
}
}

for (int j = 0; j < W * W; j++) { // check column
if (Board[row][j] == entry) {
play = false;
System.out.println("Illegal move.");
}
}
int subRow = 0;
int subCol = 0;
subRow = row / H;
subCol = column / W;

for (int i = 0; i < H; i++) { // check subgrid
for (int j = 0; j < W; j++) {
if (Board[i + H * subRow][j + W * subCol] == entry) {
play = false;
System.out.println("Illegal move.");
}
}
}
if (play == true && turn % 2 == 0) {
System.out.println("Computer's turn");
}
if (play == true && turn % 2 != 0) {
System.out.println("Human's turn");
}
turn++;

Board[row][column] = entry;
if (play) {
drawBoard(W, H);

}
}
if (computerTurn && play == false) {

{
System.out.println("Human wins!");
}
if (humanTurn && play == false) {

System.out.println("Computer wins!");
}
}
}
}

So as you can see for Mode 0, i started by making an integer to alternate between the human and computers turns and if its the computer's turn the boolean computerTurn is true and vice versa. Except whatever I've tried, a random integer won't input in the grid I've drawn.
Please and thank you. :)