I suppose your problem is to visualize the result?
Because to display a matrix of 1000 x 1000, it is very difficult in Mathematica.
If so, I suggest you to export randomA in CSV format, to display it on Excel.
countpar = 1000;
randomA = RandomReal[{1, 10}, {countpar, countpar}];
randomconst = RandomInteger[{0, 1}, {countpar, 1}];
For[i = 1, i < countpar + 1, i++,
If[randomconst[[i, 1]] != 0,
randomA[[All, i]] = 0.; randomA[[i, All]] = 0.;
randomA[[i, i]] = 1;
];
];
dy2 = ToString["C:\Users\Ahmet\Documents\test1.csv"];
st2 = OpenWrite[dy2];
For[i = 1, i <= countpar, i++,
a = ToString[randomA[[i]]];
a = StringReplace[a, "{" -> ""];
a = StringReplace[a, "}" -> ""];
WriteString[st2, a, FromCharacterCode[10]]];
Close[st2];
SystemOpen[dy2]
if your problem is to speed only the code, you can use Parallelize :
countpar = 1000;
randomA = RandomReal[{1, 10}, {countpar, countpar}];
randomconst = RandomInteger[{0, 1}, {countpar, 1}];
ClearSystemCache[];
Parallelize[
Do[If[randomconst[[i, 1]] != 0, randomA[[All, i]] = 0.;
randomA[[i, All]] = 0.;
randomA[[i, i]] = 1;], {i, 1, countpar}]];
randomconstisn't defined ! – Ulrich Neumann Feb 17 '23 at 16:19