You could use an algorithm that checks near blocks, and varies the probability depending on what is there - but I think it's largely the wrong approach.
What you want to be looking at is fractal noise types - in this case, perlin or simplex noise. If you generate noise, you'll get values from -1 to 1.
http://en.wikipedia.org/wiki/Perlin_noise
You can then adjust your water level by setting the threshhold of what makes water. For the other blocks you can run a second set of noise to switch between rock and grass. (this way you can have large patches of water, but smaller clumps of stone).
getTerrain(x,y) {
if(perlin_noise(x,y) > 0) {
if(perlin_noise(x * scale,y * scale) > 0) {
return rock
} else {
return dirt
}
} else {
return water
}
As I think the scan and toss method is overly complicated and not overly robustly scaleable, I'll suggest another method that I enjoyed:
Lay a grid across your map, breaking the map into large squares.
Generate a random number at each intersection (between 0 and 1 will work for your percentages)
Subdivide by cutting each square into 4 even squares - follow the old lines, and where you find the subdivision lines, generate a random number between the 2 adjacent points, similarly, for the center of the cross, generate a point that lies between the highest and lowest values.
Rinse, and repeat. You will get the initial randomness from the first pass, but the latter passes will give some uniformity Sorry for the psuedo-random numbers:
0-------5 0---3---5 0-1-3-4-5 011233455
| | | | | | | | | | 012344555
| | | | | 0-2-4-6-5 002445665
| | | | | | | | | | 123445666
| | 2---5---7 2-4-5-7-7 234455777
| | | | | | | | | | 233455688
| | | | | 2-3-5-5-9 223455589
| | | | | | | | | | 233455589
2-------9 2---4---9 2-4-4-5-9 234445579
This works even better for triangles, because you don't have the lost cross-bar when you sub-divide.
Of course, the absolute best result will come from combining these methods - layer upon layer, some techniques will give you great land-masses, others will give you awesome caves, others work for hills, and more will work for water-systems.