code: def random(
      m,
      n,
      density=0.01,
      format="coo",
      dtype=None,
      random_state=None,
      data_rvs=None,
  ):
      """Generates a random sparse matrix.
  
      This function generates a random sparse matrix. First it selects non-zero
      elements with given density ``density`` from ``(m, n)`` elements.
      So the number of non-zero elements ``k`` is ``k = m * n * density``.
      Value of each element is selected with ``data_rvs`` function.
  
      Args:
          m (int): Number of rows.
          n (int): Number of cols.
          density (float): Ratio of non-zero entries.
          format (str): Matrix format.
          dtype (~cupy.dtype): Type of the returned matrix values.
          random_state (cupy.random.RandomState or int):
              State of random number generator.
              If an integer is given, the method makes a new state for random
              number generator and uses it.
              If it is not given, the default state is used.
              This state is used to generate random indexes for nonzero entries.
          data_rvs (callable): A function to generate data for a random matrix.
              If it is not given, `random_state.rand` is used.
  
      Returns:
          cupyx.scipy.sparse.spmatrix: Generated matrix.
  
      .. seealso:: :func:`scipy.sparse.random`
  
      """
      if density < 0 or density > 1:
          raise ValueError("density expected to be 0 <= density <= 1")
      dtype = cupy.dtype(dtype)
      if dtype.char not in "fd":
          raise NotImplementedError("type %s not supported" % dtype)
  
      mn = m * n
  
      k = int(density * m * n)
  
      if random_state is None:
          random_state = cupy.random
      elif isinstance(random_state, (int, cupy.integer)):
          random_state = cupy.random.RandomState(random_state)
  
      if data_rvs is None:
          data_rvs = random_state.rand
  
      ind = random_state.choice(mn, size=k, replace=False)
      j = ind // m
      i = ind - j * m
      vals = data_rvs(k).astype(dtype)
      return _coo.coo_matrix((vals, (i, j)), shape=(m, n)).asformat(
          format
      )
  
file_path: cupy/cupyx/scipy/sparse/_construct.py
imports: import numpy
  import cupy
  from cupyx.scipy.sparse import _coo
  from cupyx.scipy.sparse import _csc
  from cupyx.scipy.sparse import _csr
  from cupyx.scipy.sparse import _dia
  from cupyx.scipy.sparse import _sputils
label_desc: Use image node_id 8 for calling a global function with example usage: random(m, n, density, format, dtype, random_state, data_rvs) and returns: _coo