The map number at the top of the page is used as a seed for the random number generator. The seed can be anywhere from 1 to 2,000,000,000. (That's two bilion!) Multiply that by three size and three density options and you have 18 billion possible combinations, not including colours and the grid. That's a lot! Assuming it took you 5 seconds to set the options and load a map, it would take you over 2,800 years to see them all!
The process is split into two parts. First a two-dimensional map grid is generated, second the grid is used to build an image.
Create an empty grid the size of the map. Add caves to the grid, starting with the entrance, then adding more as space is found. At this stage the "density" setting is important as the higher it is the more caves are added. Caves are rectangular.
With the caves in place add tunnels to link them all together. This is done with enough randomisation to ensure that tunnels are not all straight lines.
For each cave select a shape, resize it to the shape of the cave (including random flip and/or rotate), then paste it on the image.
Do the same with each tunnel square to finish with a single coloured matte.
Find the wall edges by scanning the image, then make the walls and the wall shadow.
Overlay the transparent matte onto the preferred base along with the walls.
The map image is now complete.
The original cave map generator used lower resolution graphics and different techniques to build the initial map. The old process produced caves that tended to have lots of tunnels coming out from a single point whereas the newly updated algorithm makes more natural looking networks of caves.
There is a lot of large image manipulation that has to go on to make a map image. For the largest image size this can be hundreds of megabytes of data in memory. Processing that can take a moment, but good things come to those who wait.
Unfortunately not. The way in which the code works is part of the "special sauce" that makes Gozzys.com work. The good news is that you can reuse the maps that are produced under a Creative Commons license.