There are many different ways. Here's one:
https://dl.dropboxusercontent.com/u/542 ... ample.capx
It's divided into multiple passes over the grid
The first pass creates a hill using basically a sine wave,
Then in that hill it creates a rock layer using a sine wave, a parabola, and some random noise with a falloff with y.
It also speckles some gold below a certain depth with some random noise with low probability.
The second pass digs out caves using bilinear interpolation over a smaller array of random values.
The third pass removes single tile wide edges, and changes dirt to grass if on top, and gives it a chance to grown down further.
This doesn't even scratch the surface of things you can do, and you can even get entirely different terrains by just tweaking numbers.