code: def sprand(m, n, density, format='csr'):
      
      m, n = int(m), int(n)
  
      # get sparsity pattern
      A = _rand_sparse(m, n, density, format='csr')
  
      # replace data with random values
      A.data = sp.rand(A.nnz)
  
      return A.asformat(format)
docs: Return a random sparse matrix.
  
      Parameters
      ----------
      m, n : int
          shape of the result
      density : float
          target a matrix with nnz(A) = m*n*density, 0<=density<=1
      format : string
          sparse matrix format to return, e.g. 'csr', 'coo', etc.
  
      Return
      ------
      A : sparse matrix
          m x n sparse matrix
  
      Examples
      --------
      >>> from pyamg.gallery import sprand
      >>> A = sprand(5,5,3/5.0)