Re: Filling a 2x2 array with random numbers such that...



Willem <willem@xxxxxxxx> writes:

manishwiz@xxxxxxxxx wrote:
) omg! Was too sleepy and typed 2x2. I can't believe it!
) Actually I meant a 2 dimensional matrix. Is it still trivial?
) I apologize for the mistake.

Well, if you have an NxN matrix, then you have 2N equations and N*N
variables. That would mean that the grid is fixed after you have randomly
picked N*N-2N numbers. (Including the two desired sums).

One easy way would be to randomly fill an (N-1)x(N-1) grid,
and then randomly select the row and column sums.
(For these last two, you will probably need to calculate a minimum so that
you won't have to fill in negative numbers at the next step.)
Then, you fill in the Nth row so that the column sums add up,
and then fill in the Nth column so that the row sums add up.

Easy peasy.

An unstated requirement, though, is probably that the random matrices
be equiprobable, or nearly.

Given the parameters of the problem, how many different combinations
(matrices) are there? Just pick an equiprobable random number in this
range, and build the corresponding matrix.


--
__Pascal Bourguignon__ http://www.informatimago.com/

CONSUMER NOTICE: Because of the "uncertainty principle," it is
impossible for the consumer to simultaneously know both the precise
location and velocity of this product.
.