import random


def create_grid(dimension, alpha):
    """ Creates a square grid with width and height of size dimension
        The parameter alpha is a measure for the density of walls in the grid
        The possible values for the grid cells are
        0 (not a wall), 1 (a wall), 2 (end cell)
        The start cell is the (0,0) cell and is assigned a value of 0
        The end cell is the upper right cell and is assigned a value of 2
    """
    row_count = dimension
    column_count = dimension
    grid = []
    for row in range(row_count):
        grid.append([])
        for column in range(column_count):
            if random.random() > alpha:
                cell_type = 1
            else:
                cell_type = 0
            grid[row].append(cell_type)
    grid[dimension-1][dimension-1] = 2
    grid[0][0] = 0
    return grid