Filling array with random digits in range
<p>I am writing a sudoku board game generator. My code looks like this:</p>

<pre><code>/**
 * Created by szubansky on 3/9/16.
 */

public class SudokuBoard {

    static int N = 9;
    static int[][] grid = new int[N][N];

    static void printGrid()
    {
        for (int row = 0; row &lt; N; row++)
        {
            for (int col = 0; col &lt; N; col++) {
                System.out.printf("%5d", grid[row][col]);
            }
            System.out.println("\n");
        }
    }

    private static boolean checkRow(int row, int num)
    {
        for( int col = 0; col &lt; 9; col++ )
            if(grid[row][col] == num)
                return false;

        return true;
    }

    private static boolean checkCol(int col, int num)
    {
        for( int row = 0; row &lt; 9; row++ )
            if(grid[row][col] == num)
                return false;

        return true;
    }

    private static boolean checkBox(int row, int col, int num)
    {
        row = (row / 3) * 3;
        col = (col / 3) * 3;

        for(int r = 0; r &lt; 3; r++)
            for(int c = 0; c &lt; 3; c++)
                if(grid[row+r][col+c] == num)
                    return false;

        return true;
    }

    public static boolean fillBoard(int row, int col, int[][] grid)
    {
        if(row==9) {
            row = 0;
            if (++col == 9)
                return true;
        }

        if(grid[row][col] != 0)
            return fillBoard(row+1, col, grid);
        for(int num=1 + (int)(Math.random() * ((9 - 1) + 1)); num&lt;=9; num++)
        {
            if(checkRow(row,num) &amp;&amp; checkCol(col,num) &amp;&amp; checkBox(row,col,num)){
                grid[row][col] = num;
                if(fillBoard(row+1, col, grid))
                    return true;
            }
        }
        grid[row][col] = 0;
        return false;
    }

    static public void main(String[] args){
        fillBoard(0, 0, grid);
        printGrid();
    }
}
</code></pre>

<p>the problem is with generating numbers in fillBoard backtrack algorithm
it basically puts 0 everywhere
when I change the num range in for loop to 10 it goes smoothly but my numbers need to be lower than 9
i can also change the beginning of backtrack fillBoard to <code>row==8</code> and <code>col==8</code> and it fills it correctly with random numbers leaving last row and last column with "0".
how to generate random numbers from 1 to 9 and fill all my grid?</p>