Generating maps can be quite difficult. I spent some time programming a procedural generator for 2D side-scrolling games with support for saving, loading and sharing presets. You can check it out on my website (www.luukdomhof.com). You could be able to data mine it for the code, make sure not to copy it though! :) It will take you quite a while to program something like that, and since you're still trying to understand it, it will probably be even harder.
~Luuk