code: def random_dag(nodes, edges):
      """Generate a random Directed Acyclic Graph (DAG) with a given number of nodes and edges."""
      G = nx.DiGraph()
      for i in range(nodes):
          G.add_node(i)
      while edges > 0:
          a = randint(0, nodes - 1)
          b = a
          while b == a:
              b = randint(0, nodes - 1)
          G.add_edge(a, b)
          if nx.is_directed_acyclic_graph(G):
              edges -= 1
          else:
              # we closed a loop!
              G.remove_edge(a, b)
      return G
  
file_path: ipyparallel/examples/dagdeps.py
imports: from random import randint
  import networkx
  import ipyparallel
label_desc: Use image node_id 2 for calling a global function with example usage: random_dag(nodes, edges) and returns: G