<p>
First of all, a random matrix can be generated by placing a random number at each of its coefficients.

Now except some very special cases (such as 2&times;2 matrix whose coefficients are either 0 or 1), a square random matrix has a very high probability of being invertible. Therefore one can first generate a matrix, test for invertibility, and restart if not.

Another method is to put special values into the coefficients of the matrix, to make sure that it is invertible. For example, to generate a random 2&times;2 matrix \([a,b;c,d]), one can put odd integers into \a and \d, and put an even integer into \c. In this way, the determinant of the matrix is odd, so it cannot be singular.