FlexGen is a flexible random map generator. It is a Java library that can be used to randomly generate maps for games and simulations. FlexGen is designed to be flexible so that you can generate any type of map that may be required for your situation. FlexGen has been created by Jeff Weston and is licensed under the BSD license.
In FlexGen, maps are composed of tiles and units. A map unit is the smallest element in a map. Map units represent the raw components present in your map. If you are generating a forest map, you will likely have map units for grass, forest, and water. If you are generating a map for a dungeon, you will likely have units for rooms, hallways, and doorways.
Map tiles are a small grid of map units. They represent a slightly larger element than map units in maps. Again with the forest example, you may have a map tile that contains half grass and half forest, and a map tile that contains grass that is split down the middle with water. You will ultimately want to create map tiles with different combinations of map units that represent the various ways the map units can be combined to form interesting features in your map.
Every type of map tile specifies what type of map tiles can be placed along each of its edges. FlexGen generates maps by randomly placing map tiles on a map such that the edges of all adjacent map tiles match this specification. By specifying the ways that map tiles can be placed adjacent to each other, you instruct FlexGen how to generate the map. Going back to the forest example, you can ensure that rivers don't just start and stop in the middle of nowhere by specying that map tiles with a river edge can only be placed adjacent to another map tile with a river edge.