Skip to main content
`Ctrl`+`K`

# gnm_random_graph

gnm_random_graph(n, m, seed=None, directed=False, *, create_using=None)

  Returns a \(G_{n,m}\) random graph.

  In the \(G_{n,m}\) model, a graph is chosen uniformly at random from the set of all graphs with \(n\) nodes and \(m\) edges.

  This algorithm should be faster than `dense_gnm_random_graph()` for sparse graphs.

  Parameters:
    n int

      The number of nodes.

    m int

      The number of edges.

    seed integer, random_state, or None (default)

      Indicator of random number generation state. See Randomness.

    directed bool, optional (default=False)

      If True return a directed graph

    create_using Graph constructor, optional (default=nx.Graph or nx.DiGraph)

      Graph type to create. If graph instance, then cleared before populated. Multigraph types are not supported and raise a `NetworkXError`. By default NetworkX Graph or DiGraph are used depending on `directed`.

  See also

  `dense_gnm_random_graph`