Games & Puzzles
Maze Generator - Random Mazes Online
Generate random mazes in any size using the recursive-backtracking algorithm. Solve manually or reveal the solution path. Free & 100% browser-based.
Click Generate to create a maze.
How to navigate
Use the arrow keys or WASD to move your position through the maze. On touch devices, swipe in the direction you want to move. Find your way from the start (typically the top-left) to the finish (typically the bottom-right).
Maze generation algorithms
Mazes are generated procedurally - no two are alike. Common generation algorithms include:
- Recursive Backtracker (DFS): the most common algorithm. Carves a path until it hits a dead end, then backtracks to the last junction and tries another direction. Produces mazes with long, winding corridors and relatively few dead ends.
- Prim’s algorithm: grows the maze from a starting cell by randomly adding adjacent walls to a frontier. Produces mazes with many short branches and a more tree-like structure.
- Wilson’s algorithm: uses loop-erased random walks to build a statistically uniform spanning tree. Generates mazes with no bias - every solvable maze is equally likely to be generated.
- Eller’s algorithm: generates the maze one row at a time, making it memory-efficient and suitable for very large mazes.
What makes a maze harder?
A maze’s difficulty is affected by:
- Number of dead ends: more dead ends means more false paths to explore.
- Solution path length: a longer solution route relative to the grid size increases difficulty.
- Grid size: larger grids contain more possibilities and require more effort to navigate.
Mazes in computing and robotics
Maze generation and solving algorithms are a classic topic in computer science because they closely model path-finding problems. The same algorithms used here - DFS, BFS, A* - are used in GPS navigation, game AI pathfinding, circuit board routing, and autonomous robot navigation.
Algorithm comparison
| Algorithm | Dead ends | Corridor style | Statistical bias |
|---|---|---|---|
| Recursive Backtracker (DFS) | Moderate | Long, winding | River bias (long passages) |
| Prim's | Many | Short, branchy | Spreads from center |
| Kruskal's | Many | Uniform, sparse | Low bias |
| Wilson's | Moderate | Irregular | Truly uniform (UST) |
| Eller's | Variable | Row-by-row | Low; memory efficient |
Solving strategies
- Right-hand rule (wall follower): keep your right hand touching the wall and walk forward. Guarantees reaching the exit if the maze is "simply connected" (no isolated walls), but fails on mazes with loops.
- Dead-end filling: identify all dead ends and fill them in from the tip back to the last junction. Repeat until no dead ends remain - the solution path is what's left.
- Breadth-first search (BFS): explores all cells layer by layer from the start, guaranteeing the shortest path. Used in GPS routing.
- A* (A-star): like BFS but uses a heuristic (usually Manhattan distance) to explore cells closest to the goal first. Faster than BFS for large mazes with a clear spatial goal.