how about:
n = 5;
(a = Table[Random[], {n}, {n}]) // MatrixForm
Table[If[i == j,
a[[i, j]] = Total[Abs[a[[i, All]]]] - Abs[a[[i, j]]]], {i, 5}, {j,
5}];
a // MatrixForm
edit(1)
I was thinking to myself that to make the above more random, I should multiply the generated elements on the diagonal by another random number > 1. Else, the way it is, the matrix is not really random, as one can figure what the element on the diagonal is by summing all the other elements on the row.
So, here is version 2 of the above
n = 5;
(a = Table[Random[], {n}, {n}]) // MatrixForm
Do[
Do[If[i == j,
a[[i, j]] =
RandomReal[{1, 10}]*(Total[Abs[a[[i, All]]]]-Abs[a[[i, j]]])
],
{i, 5}],
{j, 5}
];
a // MatrixForm
The matrix is still not exactly random, but at least a little more random than before :)
edit(2)
after having coffee, I thought that I should make the above more functional ! So I rewrote the above in what I think is a more Mathematica/functional style (no explicit Do loops).
here it is
scale = 2;
A = Table[RandomReal[], {3}, {3}]
A = ReplacePart[
A, {{i_, i_}}:> RandomReal[{1, scale}]*(Total@Abs@A[[i, All]]-Abs@A[[i, i]])]
hence, before mat was
{{0.577887, 0.825449, 0.085029},
{0.68226, 0.81484,0.903905},
{0.289007, 0.642185, 0.598648}}
after mat becomes
{{1.74871, 0.825449, 0.085029},
{0.68226, 2.15998,0.903905},
{0.289007, 0.642185, 1.58928}}
I am really starting to like this functional programming way. It also seems to make the code shorter, which is a good thing I think. Less code means less chance of a bug.