Random cluster formations, computed with zig

Nicholas Nassim Taleb, in his book, "Fooled by Randomness", has introduced me to the idea of clusters (potentially) forming randomly:

I would further illustrate the point with the study of a phenomenon well-known as cancer clusters. Consider a square with 16 random darts hitting it with equal probability of being at any place in the square. If we divide the square into 16 smaller squares, it is expected that each smaller square will contain one dart on average—but only on average. There is a very small probability of having exactly 16 darts in 16 different squares. The average grid will have more than one dart in a few squares, and no dart at all in many squares. It will be an exceptionally rare incident that no (cancer) cluster would show on the grid. Now, transpose our grid with the darts in it to overlay a map of any region. Some newspaper will declare that one of the areas (the one with more than the average of darts) harbors radiation that causes cancer, prompting lawyers to start soliciting the patients.

Statistically it absolutely makes sense, but I still wanted to verify it for fun. I combined it with me learning the zig programming language. Using python would have been times easier, but at least, I am practicing zig.

First lets create a multidimensional array and initialize it all to zeros:

var grid: [rows][cols]u8 = @splat(@splat(0));

Then we "throw the darts", by choosing a random cell in the grid, and increasing the value by one if hit:

var i: u32 = 0;
while (i < rows * cols) : (i += 1) {
    const rowrnd = rnd.uintLessThan(u32, rows);
    const coldrnd = rnd.uintLessThan(u32, cols);
    grid[rowrnd][coldrnd] += 1;
}

Now, that we have thrown the darts, I want to count how many darts fell in each "sector", by dividing the grid by a factor. For curiosity I also keep the min and max value of the total. Do ignore the O(nˆ2) please:

var sectors: [rows / factor][cols / factor]u32 = @splat(@splat(0));

for (0..rows) |row| {
    for (0..cols) |col| {
        const num = grid[row][col];
        sectors[row / factor][col / factor] += num;
    }
}
const lmin: u32 = min(sectors);
const lmax: u32 = max(sectors);
print("min: {}, max: {}\n", .{ lmin, lmax });

And then we can inspect the result. We reduce a 100x100 grid to a 25x25, and count how many darts fell in each:

clusters

The cluster with the least darts has 11, the cluster with the most darts has 39, with most sectors having a value in between.

Indeed the enunciated property holds after some superficial testing. This would presumably hold, for any type of grid size and any kind of factor.

If I am wrong, please tell my why. You can find contact info in the about page.