Create the matrix elementwise. Choose a random element from the available elements. Exclude elements on top and left of the element to be set:
exclude = [M(gt0(iy - 1), ix), M(iy, gt0(ix - 1))];
M(iy, ix) = choose(randi(numel(choose)));
I've experimented with cumsum(cumsum(randi([1, 9], 10, 15), 1), 2): There are no repetitions. Then limit the values by rem(). This was not successful. In one dimension it is working, but not in 2.