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?