One of the most well-know ways to generate mazes is using backtracking. The main concept is keep track of each cell visited, use Depth-First search to visit any cells not yet visited randomly and backtrack if there are no more non-visited neighbor cells.

Try it out interactively in iPython Notebook here: