At present, I want to generate some random matrices whose nth power is zero matrix.
mat0[n_] :=
Module[{k},
While[MatrixPower[k = RandomInteger[{1, 5}, {n, n}], 3] =!=
ConstantArray[0, {n, n}]]; k]
MatrixPower[#, 3] & /@ Table[mat0[3], 3]
A = Array[x, {3, 3}];
FindInstance[MatrixPower[A, 3] == ConstantArray[0, {3, 3}],
Flatten[A], Reals, 3]
The above code is used to get the matrix whose third power is zero matrix. But the above code has been running, what can I do to quickly get the random matrix that meets the requirements?