# Generate a Random Diagonally Dominant Matrix

I would like to write a function to generate a diagonally dominant matrix of random values. What I'm ultimately leading to is writing a code to implement the Jacobi method on this matrix in CUDA for a final project in one of my classes.

The problem is I don't really know how to do this. One idea I had was to create a random number generator and for each row of the matrix I'd check to see if the diagonally dominant criteria is satisfied. Otherwise I'd generate new numbers until it works. Then just repeat this for all the rows of the matrix. Now, I don't necessarily like this idea because for large matrices there is just no way of knowing how long it would take to generate such a matrix. Are there any known methods for creating such a matrix efficiently?

• Do you have any specific distribution on diagonally dominant matrices you'd like to sample with respect to? – Yuval Filmus Nov 25 '14 at 1:35
• No I don't...just any diagonally dominant matrix with random values. I was thinking if this becomes too difficult then what I'd do is create an nxn matrix and then just have the diagonal elements all be n and then the off diagonal elements can be set to 1. This will work although it's certainly not random. But for my purposes I think it should be ok. – user111707 Nov 25 '14 at 2:19
• Note that programming questions are offtopic here. So while asking for algorithmic insight here is fine, you'll have to go elsewhere for CUDA-specific issues. – Raphael Nov 25 '14 at 7:28
• If you want to compute just some diagonally dominant matrix that depends in some form of randomness, pick a random number for all off-diagonal elements and then set the elements on the diagonal appropriately (large enough). – A.Schulz Nov 25 '14 at 7:43