Try the stickied FAQ thread.
The key words for you would be procedural and terrain generation.
If you tried a google search for "Terraria terrain generation algorithm" you would find enough more than enough information to recreate an identical system.
It it is a relatively advanced topic though.