The problem is quite old. You have a rectangle (M x N). Must generate a random labyrinth, which has only one way. The begining is down and end is up.
I have an idea how to do it, but I think there is a specific algorithm that does this (which I don't know).