>>13433901why are you trying to generate a random walk?
i've solved this problem before for creating random connected small world graphs with arbitrary constraints, and what i did is as follows:
1) have a database of open vertices
2) have a current walk path for the walker
3) generate a list of acceptable neighbors which can continue the walk based on the last vertex added to the walk
4) randomly select a valid neighbor (you can bias the selection here if you are trying to reach some destination or structure)
5) update the walk database, neighbor database, and open vertex database.
6) check if your walk has reached its destination or whatever you want OR go to step 4
as a note, it is possible to create some kind of function to keep track of neighbors, so this checking step can be fast.
it's hard to complete a task if you don't know what the goal is.