This thread has some relevant information.
To generate random dungeons there are many ways.
The more simple of them is to create many map pieces, one for each room, and write something to automatically merge them into a single map.
Otherwise, the BEST way to do it would be writing some code to actually completely generate a map, with rooms (shapes, custom shapes) and hallways to connect them, etc. but this would be really hard.