code: def gnp_random_graph(n, p, seed=None, directed=False):
      """Returns a $G_{n,p}$ random graph, also known as an Erdős-Rényi graph
      or a binomial graph.
  
      The $G_{n,p}$ model chooses each of the possible edges with probability $p$.
  
      Parameters
      ----------
      n : int
          The number of nodes.
      p : float
          Probability for edge creation.
      seed : integer, random_state, or None (default)
          Indicator of random number generation state.
          See :ref:`Randomness<randomness>`.
      directed : bool, optional (default=False)
          If True, this function returns a directed graph.
  
      See Also
      --------
      fast_gnp_random_graph
  
      Notes
      -----
      This algorithm [2]_ runs in $O(n^2)$ time.  For sparse graphs (that is, for
      small values of $p$), :func:`fast_gnp_random_graph` is a faster algorithm.
  
      :func:`binomial_graph` and :func:`erdos_renyi_graph` are
      aliases for :func:`gnp_random_graph`.
  
      >>> nx.binomial_graph is nx.gnp_random_graph
      True
      >>> nx.erdos_renyi_graph is nx.gnp_random_graph
      True
  
      References
      ----------
      .. [1] P. Erdős and A. Rényi, On Random Graphs, Publ. Math. 6, 290 (1959).
      .. [2] E. N. Gilbert, Random Graphs, Ann. Math. Stat., 30, 1141 (1959).
      """
      if directed:
          edges = itertools.permutations(range(n), 2)
          G = nx.DiGraph()
      else:
          edges = itertools.combinations(range(n), 2)
          G = nx.Graph()
      G.add_nodes_from(range(n))
      if p <= 0:
          return G
      if p >= 1:
          return complete_graph(n, create_using=G)
  
      for e in edges:
          if seed.random() < p:
              G.add_edge(*e)
      return G
  
imports: import itertools
  import math
  from collections import defaultdict
  import networkx
  from networkx.utils import py_random_state
  from .classic import complete_graph, empty_graph, path_graph, star_graph
  from .degree_seq import degree_sequence_tree
label_desc: Use image node_id 2 for calling a global function with example usage: gnp_random_graph(n, p, seed, directed) and returns: G, G, complete_graph