Creating a random sparse precision matrix? In my current project, I want to create a random sparse precision matrix $\boldsymbol{P}=\boldsymbol{\Sigma}^{-1}$ (the inverse of a covariance matrix $\boldsymbol{\Sigma}$). My current procedure consists of using a starting with a $K$-dimensional identity matrix, then setting random entries (symmetric across the diagonal) to random values between $0$ and $1$.
However, this does not seem to yield a valid covariance matrix. If I invert $\boldsymbol{P}$ to obtain $\boldsymbol{\Sigma}=\boldsymbol{P}^{-1}$, this covariance matrix has negative values along the diagonal. Clearly, there is more to creating a valid precision matrix.
Hence my question: What am I missing? Can you recommend a procedure to create valid precision matrices?


... a $K$ dimensional identity matrix, ...

is the inverse $\rho^{-1}$ of the correlation matrix $\rho$ for $K$ uncorrelated variables ($\rho$ could be scaled to a covariance matrix). For multivariate normal distributions, this starting point specifies a maximum entropy distribution.  Your insertion of off diagonal elements reduces the entropy of the synthesized distribution.
I address related topics in my thesis in chapters 5 and 6, and an ICPRAM 2019 conference paper. See thesis equations (6.25) and (6.26).  The thesis addresses scenarios with larger correlation patterns than pairwise (stock portfolios), but the punch line is roughly

the inverse correlation matrix $\rho^{-1}$ ...
is the sum of the outer products of [K-dimensional unit-length vectors with one or two non-zero entries],
scaled by the Lagrange parameters required to enforce
[univariate and pairwise correlation] constraints.

You need to think about the distribution of number of off-diagonal elements (pairwise correlation constraints) desired, and the distribution of the partial correlation patterns you are trying to represent in the inverse correlation matrix specifying your synthesized distributions.
