Effectively chosing a random direction

Hello!

I’m trying to make a program that generates a random labyrinth, I do this by using a Randomized Depth-First (se wikipedia, http://en.wikipedia.org/wiki/Maze_generation_algorithm , for the basic idea). I have just one problem, I want to be going in randomized directions but I don’t want the program to check the same direction twice. So I want it to pick a random direction and if that “cell” has already been visited (meaning there can’t be a path going from the current cell to that cell) then I want the program to check another direction from the current cell without ever checking the same direction again (since we know it’s unavailable).
One suggestion I was considering is to create a collection and mixing it with Collection.shuffle but I’ve never used collections before and I don’t know how to use that to make the program call 4 methods in a random order that way.
Anyone have a recommendation or a good trick I can use?

Thank you!

Just pick a random direction and if it is taken add 90 degrees, and repeat.

Even if you randomly select which direction to ‘spin’ 90 degrees, it would produce different output than a purely random selection, which may be undesirable.
For pure random, see my response in the other thread. (posted there before I saw this)

Also, double thread? Merge perhaps?

Learning to use Collections and shuffling is not so bad! Suppose you create a grid of “Cells” and for each cell, create an ArrayList called neighborCells, and populate it.

Then, to shuffle the list, one only needs this line:

Collections.shuffle(neighborCells);

Any collection that extends the List interface can be used as a parameter in the above code.

To iterate through the randomized collections is easy. Just use a “for each” loop. Assuming a method called something like checkDirection():

for (Cell n: neighborCells)
{
    checkDirection(n);
}

There are better performing collections than ArrayList for this sort of thing, and neat recursive implementations for tree searching. But I am refraining from going into that because of the reluctance you expressed about Collections. I figure it’s good to first get something easy working. As a consequence, I may have aimed this answer too low for your knowledge level.

Which algo from the wiki are you thinking of implementing?