class_docstr: Base class for all Directed Graphical Models.
  
  Each node in the graph can represent either a random variable, `Factor`,
  or a cluster of random variables. Edges in the graph represent the
  dependencies between these.
  
  Parameters
  ----------
  data: input graph
      Data to initialize graph. If data=None (default) an empty graph is
      created. The data can be an edge list or any Networkx graph object.
  
  Examples
  --------
  Create an empty DAG with no nodes and no edges
  
  >>> from pgmpy.base import DAG
  >>> G = DAG()
  
  G can be grown in several ways:
  
  **Nodes:**
  
  Add one node at a time:
  
  >>> G.add_node(node='a')
  
  Add the nodes from any container (a list, set or tuple or the nodes
  from another graph).
  
  >>> G.add_nodes_from(nodes=['a', 'b'])
  
  **Edges:**
  
  G can also be grown by adding edges.
  
  Add one edge,
  
  >>> G.add_edge(u='a', v='b')
  
  a list of edges,
  
  >>> G.add_edges_from(ebunch=[('a', 'b'), ('b', 'c')])
  
  If some edges connect nodes not yet in the model, the nodes
  are added automatically. There are no errors when adding
  nodes or edges that already exist.
  
  **Shortcuts:**
  
  Many common graph features allow python syntax for speed reporting.
  
  >>> 'a' in G     # check if node in graph
  True
  >>> len(G)  # number of nodes in graph
  3
class_docstr_tok: ["Base","class","for","all","Directed","Graphical","Models",".","Each","node","in","the","graph","can","represent","either","a","random","variable",",","`","Factor","`",",","or","a","cluster","of","random","variables",".","Edges","in","the","graph","represent","the","dependencies","between","these",".","Parameters","--","--","--","--","--","data",":","input","graph","Data","to","initialize","graph",".","If","data=None","(","default",")","an","empty","graph","is","created",".","The","data","can","be","an","edge","list","or","any","Networkx","graph","object",".","Examples","--","--","--","--","Create","an","empty","DAG","with","no","nodes","and","no","edges",">",">",">","from","pgmpy.base","import","DAG",">",">",">","G","=","DAG","(",")","G","can","be","grown","in","several","ways",":","*","*","Nodes",":","*","*","Add","one","node","at","a","time",":",">",">",">","G.add_node","(","node=","'","a","'",")","Add","the","nodes","from","any","container","(","a","list",",","set","or","tuple","or","the","nodes","from","another","graph",")",".",">",">",">","G.add_nodes_from","(","nodes=","[","'","a","'",",","'","b","'","]",")","*","*","Edges",":","*","*","G","can","also","be","grown","by","adding","edges",".","Add","one","edge",",",">",">",">","G.add_edge","(","u=","'","a","'",",","v=","'","b","'",")","a","list","of","edges",",",">",">",">","G.add_edges_from","(","ebunch=","[","(","'","a","'",",","'","b","'",")",",","(","'","b","'",",","'","c","'",")","]",")","If","some","edges","connect","nodes","not","yet","in","the","model",",","the","nodes","are","added","automatically",".","There","are","no","errors","when","adding","nodes","or","edges","that","already","exist",".","*","*","Shortcuts",":","*","*","Many","common","graph","features","allow","python","syntax","for","speed","reporting",".",">",">",">","'","a","'","in","G","#","check","if","node","in","graph","True",">",">",">","len","(","G",")","#","number","of","nodes","in","graph","3"]
docstr: Returns a randomly generated DAG with `n_nodes` number of nodes with
  edge probability being `edge_prob`.
  
  Parameters
  ----------
  n_nodes: int
      The number of nodes in the randomly generated DAG.
  
  edge_prob: float
      The probability of edge between any two nodes in the topologically
      sorted DAG.
  
  latents: bool (default: False)
      If True, includes latent variables in the generated DAG.
  
  Returns
  -------
  Random DAG: pgmpy.base.DAG
      The randomly generated DAG.
  
  Examples
  --------
  >>> from pgmpy.base import DAG
  >>> random_dag = DAG.get_random(n_nodes=10, edge_prob=0.3)
  >>> random_dag.nodes()
  NodeView((0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
  >>> random_dag.edges()
  OutEdgeView([(0, 6), (1, 6), (1, 7), (7, 9), (2, 5), (2, 7), (2, 8), (5, 9), (3, 7)])
docstr_tok: ["Returns","a","randomly","generated","DAG","with","`","n_nodes","`","number","of","nodes","with","edge","probability","being","`","edge_prob","`",".","Parameters","--","--","--","--","--","n_nodes",":","int","The","number","of","nodes","in","the","randomly","generated","DAG",".","edge_prob",":","float","The","probability","of","edge","between","any","two","nodes","in","the","topologically","sorted","DAG",".","latents",":","bool","(","default",":","False",")","If","True",",","includes","latent","variables","in","the","generated","DAG",".","Returns","--","--","--","-","Random","DAG",":","pgmpy.base.DAG","The","randomly","generated","DAG",".","Examples","--","--","--","--",">",">",">","from","pgmpy.base","import","DAG",">",">",">","random_dag","=","DAG.get_random","(","n_nodes=10",",","edge_prob=0.3",")",">",">",">","random_dag.nodes","(",")","NodeView","(","(","0",",","1",",","2",",","3",",","4",",","5",",","6",",","7",",","8",",","9",")",")",">",">",">","random_dag.edges","(",")","OutEdgeView","(","[","(","0",",","6",")",",","(","1",",","6",")",",","(","1",",","7",")",",","(","7",",","9",")",",","(","2",",","5",")",",","(","2",",","7",")",",","(","2",",","8",")",",","(","5",",","9",")",",","(","3",",","7",")","]",")"]
code: def get_random(n_nodes=5, edge_prob=0.5, latents=False):
      """
      Returns a randomly generated DAG with `n_nodes` number of nodes with
      edge probability being `edge_prob`.
  
      Parameters
      ----------
      n_nodes: int
          The number of nodes in the randomly generated DAG.
  
      edge_prob: float
          The probability of edge between any two nodes in the topologically
          sorted DAG.
  
      latents: bool (default: False)
          If True, includes latent variables in the generated DAG.
  
      Returns
      -------
      Random DAG: pgmpy.base.DAG
          The randomly generated DAG.
  
      Examples
      --------
      >>> from pgmpy.base import DAG
      >>> random_dag = DAG.get_random(n_nodes=10, edge_prob=0.3)
      >>> random_dag.nodes()
      NodeView((0, 1, 2, 3, 4, 5, 6, 7, 8, 9))
      >>> random_dag.edges()
      OutEdgeView([(0, 6), (1, 6), (1, 7), (7, 9), (2, 5), (2, 7), (2, 8), (5, 9), (3, 7)])
      """
      # Step 1: Generate a matrix of 0 and 1. Prob of choosing 1 = edge_prob
      adj_mat = np.random.choice(
          [0, 1], size=(n_nodes, n_nodes), p=[1 - edge_prob, edge_prob]
      )
  
      # Step 2: Use the upper triangular part of the matrix as adjacency.
      nodes = list(range(n_nodes))
      edges = nx.convert_matrix.from_numpy_array(
          np.triu(adj_mat, k=1), create_using=nx.DiGraph
      ).edges()
  
      dag = DAG(edges)
      dag.add_nodes_from(nodes)
      if latents:
          dag.latents = set(
              np.random.choice(
                  dag.nodes(),
                  np.random.randint(low=0, high=len(dag.nodes())),
              )
          )
      return dag
  
imports: import itertools
  import networkx
  import numpy
  from pgmpy.base import UndirectedGraph
  from pgmpy.global_vars import logger
  from pgmpy.independencies import Independencies
label_desc: Use image node_id 25 for calling the DAG obj's underlying member method code with example usage: obj.get_random(n_nodes, edge_prob, latents) and returns: dag