Basic Examples (1)

Make a random rectangular grid labyrinth:

SeedRandom[3];
({{"[◼]", "RandomLabyrinth" }})[{10,20}]

Scope (2)

Make a random hexagonal grid labyrinth:

({{"[◼]", "RandomLabyrinth" }})[{8,16},"GridLayout"->"Hexagonal"]

RandomLabyrinth can be given different properties:

({{"[◼]", "RandomLabyrinth" }})[10,"Properties"]

If the properties argument is All, then an association with all properties is returned:

({{"[◼]", "RandomLabyrinth" }})[5,All,ImageSize->Tiny]

Options (1)

GridLayout (1)

The option "GridLayout" specifies the type grid graphs used to make the labyrinth. It takes the values "Rectangular" and "Hexagonal":

({{"[◼]", "RandomLabyrinth" }})[7,"GridLayout"->#,ImageSize->{Automatic,200}]&/@{"Rectangular","Hexagonal"}

Applications (3)

Make a rectangular grid labyrinth and show it together with a solution:

res=({{"[◼]", "RandomLabyrinth" }})[{12,24},{"Walls","Paths","Solution"},ImageSize->800];
Show[res["Walls"],HighlightGraph[#,#]&@Subgraph[res["Paths"],res["Solution"]]]

Make a hexagonal grid labyrinth and show it together with a solution:

res=({{"[◼]", "RandomLabyrinth" }})[{16,20},{"Walls","Paths","Solution"},"GridLayout"->"Hexagonal",ImageSize->900];
Show[res["Walls"],HighlightGraph[#,#]&@Subgraph[res["Paths"],res["Solution"]]]

Generate 100 labyrinths:

SeedRandom[55];
AbsoluteTiming[
labs=Table[({{"[◼]", "RandomLabyrinth" }})[10,{"Walls","Paths","Solution"},ImageSize->Small],100];
]

Show the histogram of the shortest path solution lengths:

Histogram[Length[#Solution]&/@labs,]

Show the labyrinths with the smallest and largest shortest paths solutions:

Show[#Walls,HighlightGraph[#,#]&@Subgraph[#Paths,#Solution],ImageSize->230]&/@SortBy[labs,Length[#Solution]&][[{1,-1}]]

Possible Issues (2)

For larger size values the labyrinth generation might be slow, especially, for hexagonal labyrinths:

AbsoluteTiming[({{"[◼]", "RandomLabyrinth" }})[50,"GridLayout"->"Hexagonal",]]

The making of rectangular labyrinths with same size parameters is faster:

AbsoluteTiming[({{"[◼]", "RandomLabyrinth" }})[50,"GridLayout"->"Rectangular",]]

Neat Examples (3)

Larger rectangular grid maze:

SeedRandom[44];
({{"[◼]", "RandomLabyrinth" }})[{30,60},EdgeShapeFunction->({Opacity[1],DarkBlue,AbsoluteThickness[6],Line[#1]}&),ImageSize->800]

A larger hexagonal grid maze with its largest connected components colored:

SeedRandom[184];
g=({{"[◼]", "RandomLabyrinth" }})[{20,40},"GridLayout"->"Hexagonal",EdgeShapeFunction->Automatic,ImageSize->800];
HighlightGraph[g,Map[Subgraph[g,#]&,ConnectedComponents[g][[1;;2]]],EdgeShapeFunction->({Opacity[1],AbsoluteThickness[4],Line[#1]}&)]

A grid of tiny labyrinths:

SeedRandom[9987];
Multicolumn[Table[({{"[◼]", "RandomLabyrinth" }})[RandomInteger[{6,7}],ImageSize->Tiny],36],6]