Skip to main content
`Ctrl`+`K`

# random_triad

random_triad(G, seed=None)

  Returns a random triad from a directed graph.

  Deprecated since version 3.3: random_triad is deprecated and will be removed in version 3.5. Use random sampling directly instead:

      G.subgraph(random.sample(list(G), 3))

  Parameters:
    G digraph

      A NetworkX DiGraph

    seed integer, random_state, or None (default)

      Indicator of random number generation state. See Randomness.

  Returns:
    G2 subgraph

      A randomly selected triad (order-3 NetworkX DiGraph)

  Raises:
    NetworkXError

      If the input Graph has less than 3 nodes.

  Examples

      >>> G = nx.DiGraph([(1, 2), (1, 3), (2, 3), (3, 1), (5, 6), (5, 4), (6, 7)])
      >>> triad = nx.random_triad(G, seed=1)
      >>> triad.edges
      OutEdgeView([(1, 2)])