I am trying to generate a random matrix with sum of entries to be equal to 2048. I am generating it by adding 1 to a random element in the matrix given number of times. I am using the following code
However when I sum all entries after a run of a Do cycle I do not obtain 2048. I usually obtain something close to it. What is worse, when I try to increase a value of a single element at the start it often gets erased and it disappears from the matrix. The code I use for this is
There are some rare instances when 300 remains in the matrix. That corresponds to the case when Do cycle did not try to add 1 into a given element. What am I missing? What is the problem within this code?