Generating Minesweeper grids
GolfScript 122 98 94 93 91 88 87 85 82 81 80 71

~]2/(\:m;~\:w*,{[.w%)\w/)]:^m\?)42{m{^*~-.*@@-.*+3&lt;},,72or 48+}if}%w/n*


Online demos:

Test Case 1: link

Test Case 2: link