I spent a couple hundred hours working on a procedural generation system for CleanFall. Most of that times grew from all the features it required. It needed to allow for infinite scalability. It needed to be fully destructible, and the blocks needed to be extremely small. On top of that, I didn't want the texture to loop every block, and I didn't want the terrain to be blocky- it needed to smooth itself.
The first step is generating the raw data. I use a 2D array of integers, where 0 represents air, -1 is banned space, and everything else represents various block types. I manipulate this raw grid through a variety of methods like Perlin noise, cellular automata, or using basic shapes with randomized, jagged edges.
I abstract simple actions into a library- this is a simple cave generator.
That block of code can generate a decent variety of shapes.
Once the data is set, a separate script is in charge of converting the array into in-game solids. Each block reads its surrounding tiles for the marching tiles algorithm, and I use binary counting to quickly set the coordinate to 1 of 16 unique block states depending on their surroundings. At the same time, I package sets of these blocks into chunks, and create a separate tile map for each one, which lets me quickly load and unload chunks during gameplay.
We get a system with optimal performance where the world's size is only limited by RAM and load times.