I'm trying to generate square grid templates to drill holes on a plate for a fragmentation experiment. The first part of the experiment I used the program below to generate uniformly random sites for drilling.
gridTemplate[msize_, ndrill_] := Module[{l},
(* msize is the size of the grid's square matrix
ndrill is the number of holes made in the plate *)
l = {};
While[Length[l] < ndrill,
l = Append[l, RandomInteger[{1, msize}, 2]] // DeleteDuplicates];
Grid[SparseArray[
MapThread[# -> Item[Style[#2, White], Background -> Gray] &, {l,
Range[ndrill]}], {msize, msize}], Frame -> All]]
It generates a grid like this:
Now, I need to implement a algorithm that randomly chooses the initial drilling site on the grid and subsequent sites should be randomly picked only in the Von Neumann neighborhood of the sites that already have been selected. I really have no clue on how to implement this, I've tried to understand how it was implemented in this thread (mathematica.stackexchange.com/q/39793/47756), but it was beyond my current understanding.
Also is there an easy way to attribute numbers to each site and then generate a list of the positions (number attributed) of the drilled sites?

Doloop. I added a way to extract the listholecoords$x$-y$-coodinates of the holes (in the order they were drilled). Hope that helps. – Henrik Schumacher Apr 17 '18 at 15:13holecountas the condition, but your solution using just the Do loop is more elegant (and simpler too). Your suggestion of using networks instead of the grids is interesting, since one of my hypothesis involves treating the material as a network of sites, and the loss of material due to perforation as removing vertexes, this way I can use shortest path measures to study the fragmentation. – nicholas80 Apr 17 '18 at 15:40Nearestfor that:nf = Nearest[(pts) -> Automatic]; Flatten[nf[holecoords]]. But note that this will find the nearest point amongpts, even ifholecoordsis not a subset of the vertex coordinates. – Henrik Schumacher Jul 23 '18 at 14:41pts = Flatten[Outer[List, Range[n], Range[m]], 1];. – Henrik Schumacher Jul 23 '18 at 14:50