How densely on average are dungeons placed in the world?

Solution 1:

There is no easy answer to this because it depends heavily on the rest of the terrain generation that has already been done before the game checks for valid dungeon placement locations.

When a chunk (a 16x16 wide piece of the world) is generated the game tries 8 times to place dungeons in the chunk, centred on a randomly-chosen block between bedrock and an altitude of 128. First it picks a dungeon shape for the location, then it checks to see if it's a legal dungeon location. It will refuse to place the dungeon if it is above ground, or if where its walls would be placed aren't exposed to air, or if six or more vertical sections of its walls would be visible. That means that it depends on there being air pockets underground, but not too many of them around the spot it randomly tried to place a dungeon.

As a result, there is no guarantee of a dungeon appearing in a chunk, and it's theoretically possible for a chunk to contain up to eight dungeons. Beyond that, it's almost impossible to say what the frequency is, since the game isn't using a simple percentage chance.

There's no way to turn off dungeon spawning. The game options claim that setting "Generate Structures" to OFF will disable dungeon generation, but in reality dungeons are generated in a part if the code that doesn't check that option. The only way to prevent dungeons from spawning is to have no legal locations for them, which can be accomplished by making a flat world that has only a few layers of ground.

Solution 2:

Dungeons are generated as the world is. Since the world is infinite, so is the number of dungeons. There has been discussion, but no conclusion, as to the frequency with which they spawn.

Worlds can be made with no dungeons by turning off structure generation at the start. According to the wiki, this is not true, tho the game claims it is.