code: def negative_sample(g, num_samples):
      """Random sample negative edges from graph, excluding self-loops,
      the result samples might be less than num_samples
      """
      num_nodes = g.num_nodes()
      redundancy = _calc_redundancy(
          num_samples, g.num_edges(), num_nodes**2
      )
      sample_size = int(num_samples * (1 + redundancy))
      edges = np.random.randint(0, num_nodes, size=(2, sample_size))
      edges = np.unique(edges, axis=1)
      # remove self loop
      mask_self_loop = edges[0] == edges[1]
      # remove existing edges
      has_edges = F.asnumpy(g.has_edges_between(edges[0], edges[1]))
      mask = ~(np.logical_or(mask_self_loop, has_edges))
      edges = edges[:, mask]
      if edges.shape[1] >= num_samples:
          edges = edges[:, :num_samples]
      return edges
  
imports: import json
  import os
  import numpy
  from ..None import backend
  from ..base import DGLError
  from ..convert import graph
  from ..sampling.negative import _calc_redundancy
  from .None import utils
  from .dgl_dataset import DGLDataset
label_desc: Use image node_id 1 for calling a global function with example usage: negative_sample(g, num_samples) and returns: edges