I am trying to create a connectivity matrix for a graph with N nodes. The connectivity rules state that it should have 1000 randomly assigned one way connections (nodes cannot be connected to themselves).
What I want to do is to generate a matrix NxN with mostly zeroes and 1000 ones in random places, but not on the main diagonal.
I really don’t have any ideas on how to achieve this. I thought about generating a matrix of random numbers between 0 and N/1000 and then making those above (N-1)/1000 to be one and the rest 0, but this isn’t very precise (I may get more or less than 1000) and I don’t know what to do about the diagonal.
What about this. Find the indices of non-diagonal elements. Choose some of those at random, and then populate those indices with ones: